Skip to content

Instantly share code, notes, and snippets.

@manjotsidhu
Created March 17, 2020 10:47
Show Gist options
  • Save manjotsidhu/ffedd150395f4acfd369aa21521150f2 to your computer and use it in GitHub Desktop.
Save manjotsidhu/ffedd150395f4acfd369aa21521150f2 to your computer and use it in GitHub Desktop.
TypeScript isFibonacci function unit testing using Jest
import isFibonacci from "./index"
var fibSeries: number[] = [0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181]
test('Test fibonnaci series from 0 to 4181', () => {
for (var i = 0; i < fibSeries.length; i++) {
expect(isFibonacci(fibSeries[i])).toBe(true)
}
})
@manjotsidhu
Copy link
Author

Output:

> jest

 PASS  src/index.spec.ts
  √ Test fibonnaci series from 1 to 100 (5ms)

  console.log src/index.ts:11
    false

  console.log src/index.ts:12
    true

  console.log src/index.ts:13
    true

  console.log src/index.ts:14
    false

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.887s
Ran all test suites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment