-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
169 additions
and
169 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,67 +1,67 @@ | ||
import { lazyAss } from '../src'; | ||
import { lazyAss } from '../src' | ||
|
||
describe('function as condition', function() { | ||
it('evaluates the function', function() { | ||
var called; | ||
var called | ||
function condition() { | ||
called = true; | ||
return true; | ||
called = true | ||
return true | ||
} | ||
|
||
lazyAss(condition); | ||
lazyAss(condition) | ||
expect(called).toBe(true) | ||
}); | ||
}) | ||
|
||
it('no result is failure', function() { | ||
function noreturn() {} | ||
|
||
expect(function() { | ||
lazyAss(noreturn); | ||
lazyAss(noreturn) | ||
}).toThrowError() | ||
}); | ||
}) | ||
|
||
it('adds condition function source to message', function() { | ||
function myCondition() {} | ||
expect(function() { | ||
lazyAss(myCondition); | ||
}).toThrowError(/myCondition/); | ||
}); | ||
lazyAss(myCondition) | ||
}).toThrowError(/myCondition/) | ||
}) | ||
|
||
it('allows anonymous functions', function() { | ||
var called; | ||
var called | ||
lazyAss(function() { | ||
return true; | ||
}); | ||
return true | ||
}) | ||
lazyAss(function() { | ||
return true; | ||
}, 'everything is ok'); | ||
return true | ||
}, 'everything is ok') | ||
lazyAss(function() { | ||
called = true; | ||
return true; | ||
}, 'everything is ok'); | ||
expect(called).toBe(true); | ||
called = true | ||
return true | ||
}, 'everything is ok') | ||
expect(called).toBe(true) | ||
|
||
expect(function() { | ||
lazyAss(function() {}); | ||
}).toThrowError(); | ||
}); | ||
lazyAss(function() {}) | ||
}).toThrowError() | ||
}) | ||
|
||
it('has access via closure', function() { | ||
var foo = 2, | ||
bar = 3; | ||
bar = 3 | ||
expect(function() { | ||
lazyAss(function() { | ||
return foo + bar === 6; | ||
}, 'addition'); | ||
return foo + bar === 6 | ||
}, 'addition') | ||
}).toThrowErrorMatchingSnapshot() | ||
}); | ||
}) | ||
|
||
it('example', function() { | ||
var foo = 2, | ||
bar = 2; | ||
bar = 2 | ||
function isValidPair() { | ||
return foo + bar === 4; | ||
return foo + bar === 4 | ||
} | ||
lazyAss(isValidPair, 'foo', foo, 'bar', bar); | ||
}); | ||
}); | ||
lazyAss(isValidPair, 'foo', foo, 'bar', bar) | ||
}) | ||
}) |
This file contains 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 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 |
---|---|---|
@@ -1,64 +1,64 @@ | ||
import { lazyAss } from '../src'; | ||
import { lazyAss } from '../src' | ||
|
||
describe('serializes circular objects', function() { | ||
var foo:any = { | ||
bar: 'bar', | ||
}; | ||
foo.foo = foo; | ||
var foo: any = { | ||
bar: 'bar' | ||
} | ||
foo.foo = foo | ||
|
||
it('can handle one circular object', function() { | ||
var msg = 'foo has circular reference'; | ||
var msg = 'foo has circular reference' | ||
expect(function() { | ||
lazyAss(false, msg, foo); | ||
lazyAss(false, msg, foo) | ||
}).toThrowErrorMatchingSnapshot() | ||
}); | ||
}); | ||
}) | ||
}) | ||
|
||
describe('serialize arguments', function() { | ||
const foo:any = function foo() { | ||
lazyAss(false, arguments); | ||
const foo: any = function foo() { | ||
lazyAss(false, arguments) | ||
} | ||
it('serializes arguments object', function() { | ||
expect(function() { | ||
foo('something'); | ||
foo('something') | ||
}).toThrowErrorMatchingSnapshot() | ||
}); | ||
}); | ||
}) | ||
}) | ||
|
||
describe('gives context to non-serializable objects', function() { | ||
it('prints keys in non-serializable objects', function() { | ||
var foo: any = { | ||
bar: 'bar', | ||
}; | ||
foo.foo = foo; | ||
bar: 'bar' | ||
} | ||
foo.foo = foo | ||
expect(function() { | ||
lazyAss(false, foo); | ||
lazyAss(false, foo) | ||
}).toThrowErrorMatchingSnapshot() | ||
}); | ||
}) | ||
|
||
it('handles several objects', function() { | ||
var foo: any = { | ||
bar: 'bar', | ||
}; | ||
foo.foo = foo; | ||
bar: 'bar' | ||
} | ||
foo.foo = foo | ||
|
||
var bar = { | ||
foo: foo, | ||
}; | ||
foo: foo | ||
} | ||
|
||
expect(function() { | ||
lazyAss(false, foo, bar); | ||
lazyAss(false, foo, bar) | ||
}).toThrowErrorMatchingSnapshot() | ||
}); | ||
}) | ||
|
||
it('can handle array with circular objects', function() { | ||
var foo:any = { | ||
bar: 'bar', | ||
}; | ||
foo.foo = foo; | ||
var foo: any = { | ||
bar: 'bar' | ||
} | ||
foo.foo = foo | ||
|
||
expect(function() { | ||
lazyAss(false, 'problem with foo', [foo]); | ||
lazyAss(false, 'problem with foo', [foo]) | ||
}).toThrowErrorMatchingSnapshot() | ||
}); | ||
}); | ||
}) | ||
}) |
This file contains 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
Oops, something went wrong.