Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.to.not.be.a.file() not working #9

Open
stefanwalther opened this issue Jun 19, 2015 · 6 comments
Open

.to.not.be.a.file() not working #9

stefanwalther opened this issue Jun 19, 2015 · 6 comments

Comments

@stefanwalther
Copy link

.to.not.be.a.file() does not work, returns true, even if the file is not existing, example:

expect( path.join( __dirname, './tmp/lessReduce/root.css' ) ).to.not.be.a.file();

... but the file is definitely not there ... but throws an asserting exception.

@ktyacke
Copy link

ktyacke commented Jan 23, 2016

Same issue here except using format:

assert.notIsFile(filePath, "Message");

This results in the error:

 value: expected 'file/path/file.txt' to exist
  AssertionError: value: expected 'filePath/file.txtt' to exist
      at Assertion.<anonymous> (node_modules/chai-fs/lib/assertions/file.js:21:53)
      at Assertion.ctx.(anonymous function) [as file] (node_modules/chai/lib/chai/utils/addMethod.js:40:25)
      at Function.assert.notIsFile (node_modules/chai-fs/lib/assertions/file.js:37:39)
      at Context.<anonymous> (test/file.js:68:16)

...I did some digging and everything seems to be in order; however, it appears that somewhere along the line the method is mapped to the isFile method (or some other method that expects it to exists as opposed to not exist).

Cheers!

Kyle

@embpdaniel
Copy link

I am also experiencing this issue:

expect('./docs/js/angular.min.js').to.not.be.a.file();

throws error:

Uncaught AssertionError: value: expected './docs/js/angular.min.js' to exist

Any ideas? :(

@meeber
Copy link

meeber commented Jun 5, 2016

@stefanwalther @ktyacke @embpdaniel

After reviewing the code and associated tests, it appears to me that this behavior was intentional.

expect(<path>).to.not.be.a.file() first asserts that the given path exists. Only if it exists, does it continue on to assert that the given path isn't a file.

That's why you're getting the message "expected path to exist" when you're asserting a non-existent path .to.not.be.a.file().

Therefore, in most cases, what you probably want to do is change your assertion to:

expect(<path>).to.not.be.a.path();

There doesn't appear to be a single assertion that allows you to test that a given path either doesn't exist or it does exist but isn't a file. Personally, I probably would've preferred .to.not.be.a.file() to have this dual effect, but at this point, in order to not break backward compatibility, it seems such a feature would need to be a new assertion as opposed to a modification to the existing one.

@justinireland
Copy link

Holy hell, I've been fighting with this all day What a stupid function that clearly does not behave as most would intend.

At least I can confirm @meeber solution works.

@dman777
Copy link

dman777 commented May 9, 2017

I hit this also. Maybe docs might want to note this behavior :)

@fluffynuts
Copy link

Goodness. I've also just spent the best part of the last hour trying to figure out why my code was broken -- when it's not. It's this flipping assertion.

Yes, @meeber's fix works, but a path which doesn't exist is not a file (or directory). This function really should not fail for a non-existent path!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants