Skip to content

Commit

Permalink
Test function handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bunysae committed May 2, 2020
1 parent 1638c09 commit f6a020f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ test('compare functions by reference', t => {
t.false(compare(a, a_).pass)
})

test('compare function by names', t => {
function a () { return 1 + 2 } // eslint-disable-line unicorn/consistent-function-scoping
function b () { return 1 + 2 } // eslint-disable-line unicorn/consistent-function-scoping

t.false(compare(a, b).pass)
})

test('objects compare even if symbol properties are out of order', t => {
const s1 = Symbol('s1')
const s2 = Symbol('s2')
Expand Down
3 changes: 3 additions & 0 deletions test/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ test('diffs diverging complex types', t => {
map([Buffer.alloc(0)]),
map([new Uint8Array()]))
t.snapshot(actual4)

const actual5 = diff(map([1, 2]), map([1]))
t.snapshot(actual5)
}
test('diffs arrays', equalLength, mapArray)
test('diffs arguments', equalLength, mapArguments)
Expand Down
18 changes: 18 additions & 0 deletions test/serialize-and-encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ test('arguments', useDeserialized, (function () { return arguments })('foo', {})
test('date', useDeserialized, new Date('1969-07-20T20:17:40Z'))
test('error', useDeserialized, new Error('foo'))
test('function', useDeserialized, function foo () {})
test('compare functions with different names', t => {
function a () { return 1 + 2 } // eslint-disable-line unicorn/consistent-function-scoping
function b () { return 1 + 2 } // eslint-disable-line unicorn/consistent-function-scoping

const original = describe(a)
const deserialized = deserialize(serialize(original))
t.false(compareDescriptors(deserialized, describe(b)))
t.not(formatDescriptor(deserialized), formatDescriptor(describe(b)))
})
test('compare deserialized function with object', t => {
function a () { return 1 + 2 } // eslint-disable-line unicorn/consistent-function-scoping
const b = { bar: 'b' }

const original = describe(a)
const deserialized = deserialize(serialize(original))
t.false(compareDescriptors(deserialized, describe(b)))
t.not(formatDescriptor(deserialized), formatDescriptor(describe(b)))
})
test('generator function', useDeserialized, function * foo () {})
test('global', useDeserialized, global)
test('promise', useDeserialized, Promise.resolve())
Expand Down
21 changes: 21 additions & 0 deletions test/snapshots/diff.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,13 @@ Generated by [AVA](https://avajs.dev).
%diffGutters.expected#+ % %object.ctor.open%Uint8Array%object.ctor.close% %list.openBracket#[%%list.closeBracket#]%%item.after#,%␊
%diffGutters.padding# %%list.closeBracket#]%`

> Snapshot 5
`%diffGutters.padding# %%object.ctor.open%Arguments%object.ctor.close% %list.openBracket#[%␊
%diffGutters.padding# % %number.open%1%number.close%%item.after#,%␊
%diffGutters.actual#- % %number.open%2%number.close%%item.after#,%␊
%diffGutters.padding# %%list.closeBracket#]%`

## diffs arrays

> Snapshot 1
Expand Down Expand Up @@ -523,6 +530,13 @@ Generated by [AVA](https://avajs.dev).
%diffGutters.expected#+ % %object.ctor.open%Uint8Array%object.ctor.close% %list.openBracket#[%%list.closeBracket#]%%item.after#,%␊
%diffGutters.padding# %%list.closeBracket#]%`

> Snapshot 5
`%diffGutters.padding# %%list.openBracket#[%␊
%diffGutters.padding# % %number.open%1%number.close%%item.after#,%␊
%diffGutters.actual#- % %number.open%2%number.close%%item.after#,%␊
%diffGutters.padding# %%list.closeBracket#]%`

## diffs boxed primitives with extra properties

> Snapshot 1
Expand Down Expand Up @@ -1089,6 +1103,13 @@ Generated by [AVA](https://avajs.dev).
%diffGutters.expected#+ % %object.ctor.open%Uint8Array%object.ctor.close% %list.openBracket#[%%list.closeBracket#]%%item.after#,%␊
%diffGutters.padding# %%object.closeBracket#}%`

> Snapshot 5
`%diffGutters.padding# %%object.ctor.open%Set%object.ctor.close% %object.openBracket#{%␊
%diffGutters.padding# % %number.open%1%number.close%%item.after#,%␊
%diffGutters.actual#- % %number.open%2%number.close%%item.after#,%␊
%diffGutters.padding# %%object.closeBracket#}%`

## diffs single line strings

> Snapshot 1
Expand Down
Binary file modified test/snapshots/diff.js.snap
Binary file not shown.

0 comments on commit f6a020f

Please sign in to comment.