Skip to content

Commit

Permalink
feat: tested several situations
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Apr 5, 2018
1 parent 7d31e0b commit 573a286
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
23 changes: 23 additions & 0 deletions __tests__/__snapshots__/arguments-as-string-spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`arguments-as-string forms a string from strings and numbers 1`] = `"foo bar 42 the last argument"`;

exports[`arguments-as-string forms string from objects 1`] = `
"{
\\"foo\\": {
\\"bar\\": 42
}
} {
\\"name\\": \\"Joe\\"
}"
`;

exports[`arguments-as-string handles circular references 1`] = `
"{
\\"foo\\": {
\\"bar\\": 42
}
} { cannot stringify arg 1, it has type \\"object\\" with keys name, ref }"
`;

exports[`arguments-as-string handles numbers 1`] = `"1 2 3 4 5 6"`;
36 changes: 36 additions & 0 deletions __tests__/arguments-as-string-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,40 @@ describe('arguments-as-string', () => {
it('is a function', () => {
expect(typeof argumentsAsString).toBe('function')
})

it('forms a string from strings and numbers', () => {
expect(argumentsAsString('foo', 'bar', 42, 'the last argument')).toMatchSnapshot()
})

it('forms string from objects', () => {
const o = {
foo: {
bar: 42
}
}
const p = {
name: 'Joe'
}
const result = argumentsAsString(o, p)
expect(result).toMatchSnapshot()
})

it('handles circular references', () => {
const o = {
foo: {
bar: 42
}
}
const p = {
name: 'Joe',
}
p.ref = p
const result = argumentsAsString(o, p)
expect(result).toMatchSnapshot()
})

it('handles numbers', () => {
const result = argumentsAsString(1, 2, 3, 4, 5, 6)
expect(result).toMatchSnapshot()
})
})

0 comments on commit 573a286

Please sign in to comment.