Skip to content

Commit

Permalink
Merge pull request #19 from fink-lang/wrappers
Browse files Browse the repository at this point in the history
feat(jest-wrapper): add spy_on, was_last_called_with, was_not_last_called_with
  • Loading branch information
kollhof authored Sep 27, 2020
2 parents e9bc3ca + e099218 commit d4e193c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 38 deletions.
68 changes: 34 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
"cz-conventional-changelog": "^3.3.0",
"jest-cli": "^26.4.2",
"npx-run": "^2.1.2",
"semantic-release": "^17.1.1"
"semantic-release": "^17.1.2"
},
"dependencies": {
"@babel/core": "^7.11.6",
"@fink/js-interop": "^1.1.0",
"@fink/std-lib": "^4.0.0"
"@fink/js-interop": "^1.1.1",
"@fink/std-lib": "^4.0.1"
}
}
15 changes: 15 additions & 0 deletions src/index.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ mock_fn = jest_.fn

mock = jest_.mock

spy_on = jest_.spyOn

require_actual = jest_.require_actual


Expand All @@ -50,30 +52,43 @@ to_not_equal = fn expected: fn expect_actual:
expect_actual.not.toEqual expected



to_match_snapshot = fn expect_actual:
expect_actual.toMatchSnapshot ()



was_called = fn expect_actual:
expect_actual.toBeCalled ()

was_not_called = fn expect_actual:
expect_actual.not.toBeCalled ()



was_called_with = fn ...expected: fn expect_actual:
expect_actual.toHaveBeenCalledWith ...expected

was_not_called_with = fn ...expected: fn expect_actual:
expect_actual.not.toHaveBeenCalledWith ...expected



was_last_called_with = fn ...expected: fn expect_actual:
expect_actual.toHaveBeenLastCalledWith ...expected

was_not_last_called_with = fn ...expected: fn expect_actual:
expect_actual.not.toHaveBeenLastCalledWith ...expected



to_throw = fn expected: fn expect_actual:
expect_actual.toThrow expected

to_not_throw = fn expected: fn expect_actual:
expect_actual.not.toThrow expected



expect = fn actual, expectation:
expectation jest_expect actual
27 changes: 26 additions & 1 deletion src/index.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
{String, Number, Error} = import '@fink/js-interop/globals'


{skip, only, describe, it, expect, any, mock, mock_fn} = import '.'
{skip, only, describe, it, expect, any, mock, mock_fn, spy_on} = import '.'
{to_equal, to_not_equal} = import '.'
{was_called, was_not_called, was_called_with, was_not_called_with} = import '.'
{was_last_called_with, was_not_last_called_with} = import '.'
{to_throw, to_not_throw} = import '.'


Expand Down Expand Up @@ -40,6 +41,7 @@ only.describe 'test utils', fn:
was_not_called

foo 'bar'
foo 'ni'

expect
foo
Expand All @@ -57,6 +59,14 @@ only.describe 'test utils', fn:
foo
was_called_with 'bar'

expect
foo
was_last_called_with 'ni'

expect
foo
was_not_last_called_with 'bar'


only.it 'test mock module virtual', fn:
test 'testing'
Expand All @@ -65,6 +75,20 @@ only.describe 'test utils', fn:
was_called_with 'testing'


only.it 'spies on obj funcs', fn:
obj = {foo: fn: 'bar'}
spy = spy_on obj , 'foo'

expect
obj.foo _
to_equal 'bar'

expect
spy
was_called



only.it 'tests exceptions', fn:
foo = mock_fn
# istanbul ignore next
Expand All @@ -86,6 +110,7 @@ only.describe 'test utils', fn:
to_equal false



describe 'plain describe', fn:
it 'ignores return value', fn:
'foo'
Expand Down

0 comments on commit d4e193c

Please sign in to comment.