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

test: added tests for unixtimestamp generation #11886

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/parallel/test-fs-timestamp-parsing-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
require('../common');
var assert = require('assert');
var fs = require('fs');
Copy link
Member

Choose a reason for hiding this comment

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

s/var/const


[undefined, null, {}, []].forEach((input) => throws(input));
Copy link
Contributor

Choose a reason for hiding this comment

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

You could probably just inline throws like you did in the "does not throw" case.


function throws(input) {
assert.throws(() => fs._toUnixTimestamp(input)
, 'Error: Cannot parse time: ' + input);
Copy link
Member

Choose a reason for hiding this comment

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

The second argument here should be either the type of error thrown or a check function. You can use common.expectsError() (see here)

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, make this second argument a regex... new RegExp(^Error: Cannot parse time: ${input}$)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jasnell I guess the regex is going to fit better...let me push the change

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make the second argument a regular expression (with ^ and $ to match the whole thing).

}

[1, '1', Date.now()].forEach((input) => {
assert.doesNotThrow(() => fs._toUnixTimestamp(input));
});