Repository navigation
Pu/issue709 #710
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
Merged
+95
−9
Merged
Pu/issue709 #710
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,17 +9,62 @@ function sleepFor( sleepDuration: number ){ | |
| } | ||
|
|
||
| describe('Interpreter - function NOW', () => { | ||
| let originalNow: () => number | ||
|
|
||
| beforeEach(() => { | ||
| originalNow = Date.now | ||
| let cnt = 20 | ||
| Date.now = () => { | ||
| cnt += 1 | ||
| return Date.parse(`1985-08-16T03:45:${cnt}`) | ||
| } | ||
| }) | ||
|
|
||
| it('works', () => { | ||
| const engine = HyperFormula.buildFromArray([ | ||
| ['=NOW()'], | ||
| ]) | ||
| const t1 = engine.getCellValue(adr('A1')) as number | ||
| expect(t1).toBeCloseTo(31275.1565856481) | ||
| expect(engine.getCellValueDetailedType(adr('A1'))).toBe(CellValueDetailedType.NUMBER_DATETIME) | ||
| sleepFor(1000) | ||
| engine.setCellContents(adr('A2'), null) | ||
| const t2 = engine.getCellValue(adr('A1')) as number | ||
| const delta = (t2-t1)*(24*60*60) | ||
| expect(delta).toBeCloseTo(1) | ||
| const delta = engine.getCellValue(adr('A1')) as number - t1 | ||
| expect(delta*24*60*60).toBeGreaterThanOrEqual(1) //internals of the engine are also using Date.now(), so the value should be actually 4 or even more | ||
|
Comment on lines
+28
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be better to have this test predictable? dateMock.mockReturnValueOnce(new Date('1985-08-16T03:45:30Z').getTime())
const t1 = engine.getCellValue(adr('A1'))
dateMock.mockReturnValueOnce(new Date('1985-08-16T03:45:30Z').getTime())
engine.setCellContents(adr('A2'), null)
const t2 = engine.getCellValue(adr('A1'))we will know exactly what time each |
||
| }) | ||
|
|
||
| it('works #2', () => { | ||
| const engine = HyperFormula.buildFromArray([ | ||
| ['=YEAR(NOW())'], | ||
| ]) | ||
| expect(engine.getCellValue(adr('A1'))).toEqual(1985) | ||
| }) | ||
|
|
||
| it('works #3', () => { | ||
| const engine = HyperFormula.buildFromArray([ | ||
| ['=MONTH(NOW())'], | ||
| ]) | ||
| expect(engine.getCellValue(adr('A1'))).toEqual(8) | ||
| }) | ||
|
|
||
| it('works #4', () => { | ||
| const engine = HyperFormula.buildFromArray([ | ||
| ['=DAY(NOW())'], | ||
| ]) | ||
| expect(engine.getCellValue(adr('A1'))).toEqual(16) | ||
| }) | ||
|
|
||
| it('works #5', () => { | ||
| const engine = HyperFormula.buildFromArray([ | ||
| ['=HOUR(NOW())'], | ||
| ]) | ||
| expect(engine.getCellValue(adr('A1'))).toEqual(3) | ||
| }) | ||
|
|
||
| it('works #6', () => { | ||
| const engine = HyperFormula.buildFromArray([ | ||
| ['=MINUTE(NOW())'], | ||
| ]) | ||
| expect(engine.getCellValue(adr('A1'))).toEqual(45) | ||
| }) | ||
|
|
||
| it('validates number of arguments', () => { | ||
|
|
@@ -29,4 +74,8 @@ describe('Interpreter - function NOW', () => { | |
|
|
||
| expect(engine.getCellValue(adr('A1'))).toEqualError(detailedError(ErrorType.NA, ErrorMessage.WrongArgNumber)) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| Date.now = originalNow | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more elegant way will be and it's clear its a mock:
I will get to NOW in the next comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will it work for the multitude of testers that we have? (
jest,jasmine,karma)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, it will not, I forgot about jasmine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should fight for some hybrid jest/jasmine mock tests and just go with what we have. But of course it is up to you