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

Fix #435: add a test for fsPromise.unlink() to delete a file that doe… #437

Merged
merged 1 commit into from Nov 27, 2018

Conversation

susantruong
Copy link
Contributor

I wrote a test for fsPromise.unlink() to delete a file that does not exist. If the file does not exist, it can not be opened, and throw an error. #435

Copy link

@itchylol742 itchylol742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Copy link
Contributor

@y2s82 y2s82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done :) I have added few minor suggestions.

describe('fsPromises.stat', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
it('should return an error if trying to delete a file that does not exist', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make code more promise-friendly, please remove done from the argument

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for your suggestion :)

it('should return an error if trying to delete a file that does not exist', function(done) {
var fsPromises = util.fs().promises;

fsPromises.unlink('/myFile')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this more promise-friendly, please return this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for your suggestion :)

expect(error).to.exist;
expect(error.code).to.equal('ENOENT');
})
.then(() => done());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this code more promise-friendly, please remove this line as done() is no longer needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for your suggestion :)

var fsPromises = util.fs().promises;

fsPromises.unlink('/myFile')
.then(result => expect(result).not.to.exist)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is also unneeded in a promise-based test, so please remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@humphd Would you please help me on this issue? Do I need to include it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove it, yes. It's not wrong to have it, but it's not doing anything we care about. With callbacks, you need to do this, because the callback gets called in both the error and success cases, so you have to examine state for both. With Promises, only one of the two conditions will happen.

@humphd
Copy link
Contributor

humphd commented Oct 9, 2018

@susantruong This looks good, but there's now a merge conflict (not your fault) because I've merged some other students' code. Let's fix this together in class later this week.

@susantruong
Copy link
Contributor Author

@humphd I have made a change that you and my classmate recommended. Would you please review it? Thanks.

…hat does not exist

Make changes to `fsPromises.unlink()` to be more promise-friendly

Added a newline to the end of the file

Made a change to fsPromises.unlink() to be more friendly

Changed the description of the promises test
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

Successfully merging this pull request may close these issues.

None yet

4 participants