Compare commits

...

188 Commits

Author SHA1 Message Date
Gregg Van Hove
2835ca3cce Bump version to 2.6.1 2017-04-26 14:18:15 -07:00
Gregg Van Hove
120c484419 Merge branch 'patch-1' of https://github.com/reinrl/jasmine into reinrl-patch-1
- Merges #1319 from @reinrl
2017-04-26 14:06:18 -07:00
Gregg Van Hove
1d62504534 Check for process.listeners as well, for GlobalErrors
- Fixes #1333
2017-04-26 13:54:07 -07:00
Gregg Van Hove
055d88eff8 Merge branch 'UziTech-ensure-function-or-undefined'
- Merges #1329 from @UziTech
- Fixes #1328
2017-04-26 13:50:11 -07:00
Tony Brix
d2b33e0c66 allow undefined as function 2017-04-26 13:49:13 -07:00
Gregg Van Hove
0c7f36a181 Merge branch 'UziTech-remove-evil'
- Merges #1330 from @UziTech
- Fixes #1325
2017-04-26 13:36:06 -07:00
Tony Brix
686d8157e5 remove eval to create spy wrapper 2017-04-26 13:34:32 -07:00
Gregg Van Hove
b771c083cb No longer try to use nextTick since node.js gets upset 2017-04-25 14:38:09 -07:00
Gregg Van Hove
fbd2ffc08b Build distribution for keys lookup fix 2017-04-25 14:35:58 -07:00
Gregg Van Hove
b3c8fb9797 Merge branch 'seanparmelee-keys-fix'
- Merges #1326 from @seanparmelee
- Fixes #1321
- Fixes #1324
2017-04-25 13:47:53 -07:00
Sean Parmelee
ef3cfe7f44 skip the test when we can’t get the propertyDescriptor 2017-04-25 12:27:32 -05:00
Sean Parmelee
0d6ecbec17 iterate through keys with a regular for loop 2017-04-25 11:28:16 -05:00
Rich Rein
7e4b8d4531 Update README.md
Made installation instructions more version-agnostic (using {#.#.#} instead of what was hard-coded to 2.0.0), corrected example HTML file (../jasmine-core/... instead of ../jasmine-2.0.0/... in the paths for the core files).
2017-04-24 12:43:40 -05:00
Gregg Van Hove
4b696fbf26 Bump version to 2.6.0 2017-04-19 14:14:39 -07:00
Gregg Van Hove
74511f5425 Merge pull request #1316 from rachelcarmena/update-introduction-url
Updating introduction url to last version
2017-04-17 13:51:33 -07:00
Rachel
3e912f7f4e Updating introduction url to last version 2017-04-17 20:30:13 +02:00
Gregg Van Hove
19b83a7434 Throw a recognizable Error message when fail outside of a spec.
Fixes #1017
2017-04-11 12:02:29 -07:00
Gregg Van Hove
98569ba0f3 Cache installed gems, so they don't need to be installed every time.
- See https://docs.travis-ci.com/user/caching/#Caches-and-build-matrices
2017-04-10 13:52:24 -07:00
Gregg Van Hove
7f11ecb62e Merge branch '1123-custom-error' of https://github.com/deckar01/jasmine into deckar01-1123-custom-error
- Merges #1298 from @deckar01
- Fixes #1123
2017-04-10 13:47:31 -07:00
Gregg Van Hove
97f8db0616 Merge branch 'gdborton-afterAll-order'
- Merges #1312 from @gdborton
- Fixes #1311
2017-04-10 13:37:04 -07:00
Gary Borton
50880fcff7 [lifecycle hooks] Make afterAll hooks operate in the fashion as afterEach.
It was discovered that afterAll hooks run in the same order that you add them,
while afterEach hooks were running in reverse order.  This commit makes their
order consistent, and adds regression tests.

Relevant issue - https://github.com/jasmine/jasmine/issues/1311
2017-04-10 07:03:37 -07:00
Gregg Van Hove
ddcae84480 Merge branch 'issue-1294' of https://github.com/toubou91/jasmine into toubou91-issue-1294
- Merges #1300 from @toubou91
- Fixes #1294
2017-04-07 17:42:17 -07:00
Gregg Van Hove
9d6a95d9ba Merge pull request #1301 from toubou91/gitignore-update
Gitignore update
2017-04-07 17:28:39 -07:00
Thodoris Bais
0d3b2b2f8e Added iml files to gitignore 2017-04-04 07:20:10 +02:00
Thodoris Bais
08f046c24c Added infinity methods, with tests 2017-03-27 00:04:43 +02:00
Jared Deckard
90c87140ac Expect an undefined error to be passed to the expectation result 2017-03-24 14:50:54 -05:00
Jared Deckard
25d9a396aa Test that custom matchers can supply custom errors 2017-03-24 14:12:33 -05:00
Jared Deckard
c42b1972e2 Allow the matcher provide a custom error message 2017-03-24 14:12:33 -05:00
Gregg Van Hove
7f8f2b5e7a Update jsDocs to something close to full coverage for public API
- #596
2017-03-23 12:20:08 -07:00
Gregg Van Hove
9cb2f06aa6 Add a first pass at jsdoc.
[##130415655] #596
2017-03-21 11:36:41 -07:00
Gregg Van Hove
a37b6c0d32 Merge branch 'master' of https://github.com/mmmichl/jasmine into mmmichl-master
- Merges #1283 from @mmmichl
2017-03-14 17:50:28 -07:00
Gregg Van Hove
5533d1a920 Fix casing for PhantomJS is userAgent check 2017-03-14 14:43:44 -07:00
Gregg Van Hove
75e652d6a7 Cleanup toThrowError constructor lookup to work in older IE
- Also use the existing browser detection for phantom
2017-03-14 14:26:17 -07:00
Gregg Van Hove
e1f7ca51da Merge branch 'issue-1252' of https://github.com/anseki/jasmine into anseki-issue-1252
- Merges #1275 from @anseki
- Fixes #1252
2017-03-10 14:36:22 -08:00
Gregg Van Hove
538ae7b9ac Merge branch 'foretagsplatsen-toHaveBeenCalledBefore' 2017-03-10 09:57:21 -08:00
Gregg Van Hove
2ea41d3e27 Merge branch 'toHaveBeenCalledBefore' of https://github.com/foretagsplatsen/jasmine into foretagsplatsen-toHaveBeenCalledBefore
- Merges #1242 from @DamienCassou
2017-03-10 09:57:03 -08:00
Gregg Van Hove
bd9ae3a25b Fix syntax error 2017-03-07 17:05:12 -08:00
Gregg Van Hove
1042c9a2dd Collect unhandled exceptions and pass them to the current runnable
Fixes #529
Fixes #937
2017-03-07 16:32:11 -08:00
Gregg Van Hove
92e7436db2 Make sure the unlink is explicitly synchronous 2017-03-07 14:07:37 -08:00
Gregg Van Hove
74fe7fb85b Only have code climate grade the src 2017-03-01 16:29:10 -10:00
Gregg Van Hove
7e0fd79b3b Exclude some more stuff from codeclimate 2017-03-01 16:18:40 -10:00
mmmichl
8807bbb850 Pretty print objects passed to fail method
Fixes #1090
2017-02-26 19:25:02 +01:00
Damien Cassou
c93f35fbc8 fixup! Add toHaveBeenCalledBefore matcher 2017-02-20 10:55:23 +01:00
Damien Cassou
4cfdd06700 Add toHaveBeenCalledBefore matcher
This matcher makes sure the 'actual' spy is called before the
'expected' spy.

This code has been written in cooperation with Benjamin Van Ryseghem.
2017-02-20 09:52:14 +01:00
anseki
19b89d437e Skip a spec in PhantomJS that has bugs about iframe 2017-02-16 14:50:24 +09:00
Gregg Van Hove
43f96d3ecd Update gem authors 2017-02-15 17:00:17 -08:00
Gregg Van Hove
ac42bd9b35 More emeritus maintainers 2017-02-15 16:54:28 -08:00
Gregg Van Hove
9fbd0ba551 Nicer error messages for spyOn when null is provided
Fixes #1258
2017-02-15 15:55:27 -08:00
Gregg Van Hove
52876a7bf2 Merge branch 'bugfix-non-fn-args' of https://github.com/voithos/jasmine into voithos-bugfix-non-fn-args
- Merges #1222 from @voithos
- Fixes #1004
2017-02-15 15:18:50 -08:00
Gregg Van Hove
2eec3427e8 Re-generate files for new year in copyright
- Also read from env variable for sauce connect path
2017-02-15 15:15:58 -08:00
anseki
ed23254865 fix #1252 2017-02-10 17:17:39 +09:00
Gregg Van Hove
137e7e94d3 Merge pull request #1249 from Scottkao85/patch-1
Update MIT.LICENSE for new year
2017-01-02 12:14:44 -08:00
Gregg Van Hove
923b8fe9c4 Merge pull request #1248 from Nebojsaa/patch-1
Update README.md for new year
2017-01-02 12:14:27 -08:00
Scott Kao
61cc1eec66 Update MIT.LICENSE
update copyright year to 2017
2017-01-02 10:52:58 -08:00
Nebojsa Komnenovic
04be4c4583 Update README.md 2017-01-02 16:13:17 +01:00
Zaven Muradyan
b59ac96b51 Require arguments to beforeEach, it, etc, to be actual functions 2016-12-27 23:53:35 -08:00
Gregg Van Hove
be6ff8b24c Remove unused message param from Suite#pend
- See #1132
2016-12-02 10:08:39 -08:00
Gregg Van Hove
da2005fe97 Merge branch 'beforeall-in-xdescribe' of https://github.com/voithos/jasmine into voithos-beforeall-in-xdescribe
- Merges #1225 from @voithos
- Fixes #1175
2016-12-02 09:56:36 -08:00
Ben Christel
41a813521b Fix tests for toEqual diff output in IE
- Merges #1236 from @benchristel
2016-11-30 15:34:39 -08:00
Gregg Van Hove
54e7a82ef3 Merge branch 'benchristel-eq-diffs'
- Merges #1163 from @benchristel
- Fixes #675
2016-11-16 18:01:42 -08:00
Ben Christel
d5e6bf47ed Make toEqual matcher report the difference between objects
- Mismatches deep within object/array structures are pinpointed with a JsonPath-like syntax.
2016-11-14 22:08:34 -08:00
Gregg Van Hove
5a76e59d5b Merge branch 'spyOnProperty2' of https://github.com/celluj34/jasmine into celluj34-spyOnProperty2
- Merges #1203 from @celluj34
- Merges #1008 from @smacker
- Fixes #943
2016-11-04 14:36:56 -07:00
Gregg Van Hove
f5cfa2a4c1 Merge branch 'master' of https://github.com/d-reinhold/jasmine into d-reinhold-master
- Merges #1046 from @d-reinhold
- Fixes #510
2016-11-04 10:29:09 -07:00
Zaven Muradyan
c21bdaf35d Fix bug where before/afterAll were being executed in disabled suites. 2016-10-23 20:40:58 -07:00
Pivotal
369e8cc08b Merge branch 'mockMethodsShortcut' of https://github.com/mbildner/jasmine into mbildner-mockMethodsShortcut
- Merges #1101 from @mbildner
2016-10-17 15:53:05 -07:00
Gregg Van Hove
0e9b9a11c3 Fix tests for new stack clearing in IE 2016-10-14 15:53:00 -07:00
Gregg Van Hove
9750ae59e7 Update env integration specs now that we're really async 2016-10-14 10:13:27 -07:00
Gregg Van Hove
2f01f64249 Build distribution for clear stack implemenation 2016-10-14 09:48:11 -07:00
Gregg Van Hove
17c89c69d6 Separate clear stack and run it after each spec
[finishes #50197985][fix #109418332]
- Fixes #985
- Fixes #945
- Fixes #366
2016-10-14 09:21:49 -07:00
Gregg Van Hove
d85d6dd4b8 Now that it's valid syntax, make the specs work right with for 2016-09-28 12:19:18 -07:00
Gregg Van Hove
ff85714b24 syntax for a for loop is different than forEach 2016-09-28 11:52:18 -07:00
Gregg Van Hove
0d1a9a72d9 Fix spy arity stuff to work in IE8 2016-09-28 11:49:07 -07:00
Gregg Van Hove
63cc6687ff require newer jasmine-npm 2016-09-28 11:04:01 -07:00
Gregg Van Hove
75a5681c5e Merge branch 'kapke-spy-arity-preservation' 2016-09-28 10:52:17 -07:00
Gregg Van Hove
9df1edbdc9 Use the passed in env to pend browsers so IE8 works 2016-09-28 10:40:53 -07:00
Gregg Van Hove
5279e7a8c4 Checking for Set isn't browser dependant 2016-09-27 16:11:43 -07:00
Gregg Van Hove
c2e2bd7c91 Merge branch 'spy-arity-preservation' of https://github.com/kapke/jasmine into kapke-spy-arity-preservation
- Merges #1055 from @kapke
- Fixes #991
2016-09-27 15:42:45 -07:00
Gregg Van Hove
bad9c63bf7 Properly skip Set tests in browsers that don't really support it 2016-09-27 15:36:01 -07:00
Gregg Van Hove
05097b3e42 Merge branch 'set-equality' of https://github.com/alur/jasmine into alur-set-equality
- Merges #1067 from @alur
2016-09-27 13:37:57 -07:00
Gregg Van Hove
1efed4c156 Update pretty print specs to work in IE8 2016-09-27 12:26:02 -07:00
Gregg Van Hove
f4849f6401 Merge branch 'pretty-print-cross-frame-objects' of https://github.com/thatfulvioguy/jasmine into thatfulvioguy-pretty-print-cross-frame-objects
- Merges #1091 from @thatfulvioguy
- Fixes #1087
2016-09-27 11:40:01 -07:00
Gregg Van Hove
ec2ae4d521 Merge branch 'custom-testers-in-asymmetric-matchers' of https://github.com/joeyparrish/jasmine into joeyparrish-custom-testers-in-asymmetric-matchers 2016-09-27 11:01:45 -07:00
Greg Cobb
ac3d64cf84 Merge pull request #1215 from mattc41190/patch-1
Fix bad url
2016-09-22 23:03:49 -07:00
Matthew Cale
2d3c8c9f26 Fix bad url
Current README returns 404 when contributors guide is clicked.
2016-09-22 21:23:35 -05:00
Gregg Van Hove
6816bc4252 Update to 2.5.2 2016-09-16 17:19:59 -07:00
Gregg Van Hove
04bb56a5b5 Allow currently registered reporters to be cleared
- jasmine/jasmine-npm#88
2016-09-16 16:02:08 -07:00
Greg Cobb
ed31b9b844 Add ISSUE_TEMPLATE for github issues 2016-09-16 10:26:11 -07:00
Gregg Van Hove
4e47b78f1f Use isFunction to check for functionness in callFake
- Fixes #1191
2016-09-14 16:06:44 -07:00
Henry Blyth
8e23c26383 Make spyOnProperty available in tests
Needed adding to the env and require interface
2016-09-12 18:22:58 -05:00
Sukharev Maxim
56191cfb2e Implement spies for get/set functions on accessor properties 2016-09-12 18:22:58 -05:00
Gregg Van Hove
8624a52ee0 Don't auto install phantom since it doesn't seem to work on travis 2016-09-07 15:48:20 -07:00
Gregg Van Hove
a4b92b34f4 Update to 2.5.1 2016-09-07 14:31:18 -07:00
Gregg Van Hove
3486e8d166 Merge branch '1189' of https://github.com/seanparmelee/jasmine into seanparmelee-1189
- Merges #1193 from @seanparmlee
- Fixes #1189
2016-09-01 21:11:07 -07:00
Gregg Van Hove
8366ef9be5 Merge branch 'fix' of https://github.com/logankd/jasmine into logankd-fix
- Merges #1192 from @logankd
- Fixes #1188
2016-09-01 20:44:13 -07:00
Gregg Van Hove
ab0567c665 Generated file for date tick fix 2016-09-01 20:41:51 -07:00
Sean Parmelee
8676bbf11a fallback on assignment when a spy cannot be deleted 2016-09-01 13:39:25 -05:00
Kevin Logan
c0a9d20a02 fix for issue #1188 2016-09-01 10:59:19 -05:00
Gregg Van Hove
c7cc3b4a29 Properly tick date along with clock
- Specifically when there aren't functions scheduled at the ticks

Fixes #1190
2016-08-31 21:24:01 -07:00
Gregg Van Hove
5a2e1b0082 Update to 2.5.0 2016-08-30 21:23:08 -07:00
Gregg Van Hove
f196faf0bb Update anonymous constructor pretty print specs to work in IE 2016-08-25 15:29:32 -07:00
Gregg Van Hove
850204dfb8 Merge branch 'prettyPrintCustomConstructortoString' of https://github.com/mbildner/jasmine into mbildner-prettyPrintCustomConstructortoString
- Fixes #1019
- Merges #1099
2016-08-15 15:50:59 -07:00
Gregg Van Hove
7bda3bd728 Build distribution 2016-08-15 09:41:48 -07:00
Gregg Van Hove
b9c25e88b9 Merge branch 'callfake-better-error' of https://github.com/kapke/jasmine into kapke-callfake-better-error
- Merges #1059
- Fixes #1016
2016-08-15 09:34:03 -07:00
Gregg Van Hove
13228c304e Add gulp-jasmine-browser link to readme
Close #1089
2016-08-15 09:30:38 -07:00
Greg Cobb
da18479422 Merge pull request #1170 from benchristel/how-to-test-in-ie
Add instructions for testing in IE
2016-07-25 21:59:23 -07:00
Greg Cobb
ba211e4913 Update codeclimate.yml
[#1171]
2016-07-25 21:36:57 -07:00
Greg Cobb
5f9a965d7c Exclude lib directory from codeclimate
- Generated files show up as duplicates of src

[#1171]
2016-07-25 21:11:44 -07:00
Ben Christel
3ff59835ea Add instructions for testing in IE 2016-07-25 10:20:43 -07:00
Greg Cobb
9fedf74f32 Build distribution 2016-07-24 22:38:36 -07:00
Greg Cobb
0339fc500a Merge pull request #1169 from benchristel/fix-build
Fix the build in ie8
2016-07-24 22:20:55 -07:00
Ben Christel
227b0c62a3 Make the build pass in ie8
- pending() throws an exception in ie8. I have not dug into the root cause.
- iframe.contentWindow.eval() isn't supported in ie8
2016-07-24 21:48:11 -07:00
Greg Cobb
3de60067f0 Merge pull request #1158 from benchristel/move-functions-to-higher-scope
Restructure eq code and tests
2016-07-21 21:28:45 -07:00
Ben Christel
cb1001e6c2 De-dup test setup
- Move environment-specific tests for toEquals into describe blocks so the check for the environment can be shared
2016-07-21 12:26:43 -07:00
Ben Christel
d9ded15c45 Move functions in to a higher scope
- Prevents them from accessing eq's local vars, which could cause bugs.
2016-07-21 12:10:37 -07:00
Ben Christel
a0bce8031e Test comparison of objects from different frames 2016-07-21 12:10:37 -07:00
Greg Cobb
7f7dda7a2c Merge pull request #1162 from amavisca/update-dev-dependencies
Update devDependencies and fix issues from this
2016-07-20 20:18:57 -07:00
Chris Amavisca
15f92b226c Update devDependencies and fix issues from this
- Point to npm released version of jasmine node runner
2016-07-20 20:11:52 -07:00
Greg Cobb
99aa2247b6 Build distribution 2016-07-19 23:00:25 -07:00
Greg Cobb
314eb63552 Merge pull request #1129 from gregeinfrank/remove-runnable-lookup-table
Remove runnableLookupTable which is no longer used
2016-07-18 23:39:15 -07:00
Greg Cobb
bd6ca98f9d Revert "Merge pull request #1151 from amavisca/update-dev-dependencies"
This reverts commit eee75d8eed, reversing
changes made to 5e0ebadb3d.
2016-07-18 23:28:50 -07:00
Greg Cobb
eee75d8eed Merge pull request #1151 from amavisca/update-dev-dependencies
Upgrade devDependencies glob and shelljs
2016-07-18 23:00:34 -07:00
Greg Cobb
5e0ebadb3d Merge pull request #1155 from benchristel/arrays-properties-bug
Make `toEqual` pass for arrays with equivalent properties
2016-07-18 22:56:20 -07:00
Ben Christel
738c10fd43 Make toEqual pass for arrays with equivalent properties
- Fixes a bug caused by accidental use of a closure variable
2016-07-18 16:48:00 -07:00
Greg Cobb
8c9ffe3144 Merge pull request #1152 from amavisca/update-travis-ruby
Update ruby version on travis to let rack install
2016-07-14 22:28:50 -07:00
Chris Amavisca
ab2c916c3a Update ruby version on travis to let rack install 2016-07-14 19:57:08 -07:00
Chris Amavisca
290fb3fdcd Upgrade devDependencies glob and shelljs 2016-07-14 19:46:32 -07:00
Joey Parrish
de7b7c029e Pass custom testers to asymmetric testers
This allows custom equality testers to affect asymmetric matches.
This avoid suprises when combining addCustomEqualityTester with
objectContaining or arrayContaining.

Closes #1138
2016-06-23 14:33:39 -07:00
Greg Einfrank
e13c7a55a9 Remove runnableLookupTable which is no longer used 2016-06-08 10:59:42 -07:00
Pivotal
7a62969a14 createSpyObj may use object for method->response shorthand
examples:

```JavaScript
var mySpy = jasmine.createSpyObj("mySpy", { getAge: 55, getLanguage: "JavaScrizzle" });

var age = mySpy.getAge();

expect(age).toEqual(55);
expect(mySpy.getAge).toHaveBeenCalled();
```

Also does:

Add "isObject_" method to utils to make it easier for "createSpy" to support an array or object of stubs
2016-04-25 17:10:22 -04:00
Pivotal
604cd6132f Prettyprint objects whose constructors have custom toString method
- when the constructor has a name, print the name
- when the constructor does not have a name, print `<anonymous>`

[Fixes issue 1019](https://github.com/jasmine/jasmine/issues/1019)
2016-04-25 14:23:48 -04:00
Fulvio Valente
2710bdfc5e Correctly pretty print objects from other contexts (e.g. iframes) and which do not override toString
Fixes #1087
2016-04-11 18:51:04 +01:00
Gregg Van Hove
f6da084642 Merge branch 'patch-1' of https://github.com/skupr/jasmine into skupr-patch-1
- Merges #1079 from @skupr
- Fixes #964
2016-03-26 21:28:46 -07:00
Gregg Van Hove
6c0224414c Generate combined file for previous features 2016-03-26 21:27:04 -07:00
Stanislav Kupryakhin
c302545ba4 Fix jasmine setup in Electron environment
Fix for issue  #964
2016-03-21 08:38:27 +06:00
slackersoft
954a6a0091 Merge branch 'feat/improveErrorMessages' of https://github.com/dhoko/jasmine into dhoko-feat/improveErrorMessages
- Merges #1026 from @dhoko
- Fixes #1025
2016-03-18 10:59:31 -07:00
slackersoft
11cfaae42a Merge branch 'marneborn-bluebird3.0-warnings'
- Merges #1062 from @marneborn
- Fixes #992
2016-03-11 09:13:43 -08:00
Erik Welander
927cc011d6 Added support for ES6 sets to toContain and toEqual. 2016-03-04 02:09:59 -08:00
Mikael Arneborn
6cf2d94f73 The done function now returns null 2016-03-03 08:55:01 -08:00
Mikael Arneborn
b578e72c8f Added failing test for done returning null 2016-03-03 08:54:46 -08:00
Gregg Van Hove
1da6c7cf85 Merge branch 'add-editorconfig' of https://github.com/kapke/jasmine into kapke-add-editorconfig
- Merges #1058
- Fixes #1057
2016-03-01 17:50:59 -08:00
Gregg Van Hove
87e808282b Always quote the browser version so nothing converts it to a float 2016-03-01 17:34:24 -08:00
dhoko
14067d0785 Improve errors with the domaine and how to use the API 2016-02-29 10:33:45 +01:00
Dominick Reinhold
d1a94bcf50 When the HtmlReporter has a 'spec' query param, the spec list only shows matching specs/suites 2016-02-28 22:47:10 -08:00
Andrzej Kopeć
bbf3f6825c Improve error message when passing a non-function to callFake 2016-02-28 21:37:28 +01:00
Andrzej Kopeć
9b653b9dcb Add .editorconfig file 2016-02-28 18:33:39 +01:00
Gregg Van Hove
b6798cdb06 Html Reporter shows error bar for errors from a global afterAll
Issue #811
2016-02-25 16:12:15 -08:00
Gregg Van Hove
dbd198f7d0 Allow expectations in a global beforeAll or afterAll
- Report afterAll failures in jasmineDone
- Issue #811
2016-02-25 15:01:47 -08:00
Gregg Van Hove
5583b6f954 Top-level specs should compute fullName the same as Suites
- No longer include "Jasmine__TopLevel__Suite"
2016-02-25 14:29:35 -08:00
Gregg Van Hove
db8e636021 Add combined file for inherited spies 2016-02-25 14:25:40 -08:00
Andrzej Kopeć
90dea9ab38 Now spies preserve original function arity 2016-02-25 21:43:18 +01:00
Gregg Van Hove
ebbefafc26 Turn the describe error spec back on and update for new code 2016-02-25 10:04:31 -08:00
Gregg Van Hove
b66ffc1277 Merge branch 'spy-inherited-methods' of https://github.com/benchristel/jasmine into benchristel-spy-inherited-methods
- Merges #1036
- Fixes #737
2016-02-22 14:11:00 -08:00
Gregg Van Hove
5458f2f18d Array equality treats undefined elements as equal however they got in there
- Fixes #786
2016-02-22 11:06:59 -08:00
Gregg Van Hove
602f5bc08a Merge branch 'fallback-report' of https://github.com/mauricioborges/jasmine into mauricioborges-fallback-report
- Merges #1009
2016-02-22 10:20:48 -08:00
Gregg Van Hove
4e4cd30965 Merge pull request #1047 from d-reinhold/bundle-exec-compass
Grunt task for compass should prefix command with 'bundle exec'

- Merges #1047
2016-02-18 17:48:10 -08:00
Gregg Van Hove
7224c6adf2 Merge branch 'fix-eq-for-edge' of https://github.com/everedifice/jasmine into everedifice-fix-eq-for-edge
- Merges #1041
2016-02-18 16:48:33 -08:00
Gregg Van Hove
5bdd7e8fbf Merge branch 'issue-931-respy' of https://github.com/guy-mograbi-at-gigaspaces/jasmine into guy-mograbi-at-gigaspaces-issue-931-respy
- Merges #953
- Fixes #931
2016-02-18 11:40:01 -08:00
Gregg Van Hove
1e0381a495 Update describe error message to no longer assume errant args are done
Fixes #896
2016-02-18 09:31:31 -08:00
Gregg Van Hove
c454658c54 Merge branch 'rullopat-greater-than-or-equal-less-than-or-equal-matchers'
- Merges #1049
- Fixes #1013
2016-02-17 15:46:05 -08:00
Patrizio Rullo
b7d8b0de71 Add toBeGreatThanOrEqual and toBeLessThanOrEqual matchers
- Implements issue #1013
2016-02-18 00:13:26 +01:00
Gregg Van Hove
342f0eb9a3 Merge branch 'logankd-master'
- Support call count of 0 with toHaveBeenCalledTimes matcher

- Merges #1048
- Fixes #994
2016-02-17 10:33:27 -08:00
Kevin Logan
44b56093e7 #1048 - fixed toThrow expectation 2016-02-17 12:16:54 -06:00
Kevin Logan
bee8132848 #1015 - revert formatting and spacing 2016-02-17 12:09:26 -06:00
Kevin Logan
e5c744f3dc #1015 use isNumber fuction to check for empty expected argument. This will allow 0 to be passed in. 2016-02-17 12:03:06 -06:00
Gregg Van Hove
4fb5aa14b8 Merge branch 'issue1010' of https://github.com/bodawei/jasmine into bodawei-issue1010
- Merges #1011
- Fixes #1010
2016-02-16 15:41:42 -08:00
Gregg Van Hove
43cd73938d Merge branch 'remove-extra-topSuite-constructor-param' of https://github.com/jurko-gospodnetic/jasmine into jurko-gospodnetic-remove-extra-topSuite-constructor-param
- Merges #1006
2016-02-16 15:23:05 -08:00
Gregg Van Hove
f38e8e9235 Merge branch 'cloned-args-on-calltracker' of https://github.com/a-r-d/jasmine into a-r-d-cloned-args-on-calltracker
- Merges #1000
- Fixes #872
2016-02-16 15:00:49 -08:00
Gregg Van Hove
fcd5a1948b Merge branch 'skipped-links-with-random' of https://github.com/basawyer/jasmine into basawyer-skipped-links-with-random 2016-02-16 09:43:33 -08:00
Mauricio Borges Silva
6489b0f400 Add support on Env to provide fallback report 2016-02-15 23:12:05 -02:00
Mauricio Borges Silva
5e3582d8e7 Add support to fallback report providing on ReportDispatcher 2016-02-15 23:12:05 -02:00
Dominick Reinhold
33151ed9eb Grunt task for compass should prefix command with 'bundle exec'
- Since we're stating that compass is a development dependency in our
  gemspec, and we use bundle to install it, we should make sure that
  grunt is using the correct (bundled) version of compass.

- This is especially important since many of the older versions of compass
  are buggy (see https://github.com/gruntjs/grunt-contrib-compass/issues/204)
2016-02-15 11:39:21 -08:00
minhyeong-kim
3f27ff1c7c chore: fix jshint error 2016-02-04 17:47:17 +09:00
minhyeong-kim
b59cacf131 refactor: fix Edge freezing issue for matcherUtils#eq
fix Microsoft Edge freezing when recursive comparing
2016-02-04 17:09:03 +09:00
Ben Christel
d6f1f8dec5 Correctly teardown spies on inherited methods
- If the spied method is not an own property of the object being spied
  upon, the method is deleted from the object on teardown instead of
  being set to the original implementation.

- #737
2016-02-01 17:45:47 -08:00
Gregg Van Hove
e0541eca80 Merge pull request #1021 from pra85/2016
Update license year range to 2016
2016-01-17 15:24:53 -08:00
Prayag Verma
8b7cb21874 Update license year range to 2016 2016-01-18 01:13:22 +05:30
Blake Sawyer
ee0ff3b6c8 Persist randomize param in 'run all' links 2016-01-14 20:58:15 -05:00
DJ Burrowes
65241565c5 Reverse order that spies are cleared up.
Fixes #1010
2016-01-03 19:14:57 -08:00
Jurko Gospodnetić
a047115eef remove extra topSuite queueRunner construction parameter
The `Suite` constructor function does not expect or use the its only `attrs`
parameter's `queueRunner` attribute, so setting it serves no purpose and
only clutters the code and makes it more difficult to understand.
2015-12-26 21:49:45 +01:00
Gregg Van Hove
0d4c8d13bb build distribution file for mockDate changes 2015-12-22 15:25:38 -08:00
Gregg Van Hove
17c5e2b10d Merge branch 'fix-clock-date' of https://github.com/andrewiggins/jasmine into andrewiggins-fix-clock-date
Fixes #915
Merges #980
2015-12-22 15:18:58 -08:00
Aaron DEcker
fa71928cad changed arg cloner to be safe on older browsers 2015-12-22 00:35:36 -05:00
Aaron DEcker
3e91ac0889 add option to shallow clone args in call tracker 2015-12-22 00:27:51 -05:00
Gregg Van Hove
79206ccff5 Rename j$ to jasmineUnderTest for specs
- Clarifies what it is for when writing tests
- No longer named the same as the `jasmine` that is injected into live
  code
2015-12-03 17:23:32 -08:00
Gregg Van Hove
a95c2cfe3f Bump version to 2.4.1 2015-12-03 16:06:51 -08:00
Gregg Van Hove
e2e2d1b343 Revert #908
- Run `afterEach` in reverse order declared as before
2015-12-03 16:02:32 -08:00
Andre Wiggins
c8b212f278 make DelayedFunctionScheduler update the mockDate 2015-11-20 03:45:57 -08:00
guy-mograbi-at-gigaspaces
e7dbc75fc2 feat(spy): add option to respy
will not throw error if spyOn called on a spy

fixes #931
2015-10-24 08:37:33 +03:00
152 changed files with 7850 additions and 2386 deletions

16
.codeclimate.yml Normal file
View File

@@ -0,0 +1,16 @@
languages:
JavaScript: true
ratings:
paths:
- "src/**/*.js"
exclude_paths:
- "lib/**"
- "dist/*"
- "grunt/**"
- "images/*"
- "**/*.md"
- "**/*.yml"
- "**/*.json"
- "**/*.scss"
- "**/*.erb"
- "*.sh"

16
.editorconfig Normal file
View File

@@ -0,0 +1,16 @@
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
[*.{js, json, sh, yml, gemspec}]
indent_style = space
indent_size = 2
[{Rakefile, .jshintrc}]
indent_style = space
indent_size = 2
[*.{py}]
indent_style = space
indent_size = 4

View File

@@ -115,6 +115,15 @@ Jasmine uses the [Jasmine NPM package](http://github.com/jasmine/jasmine-npm) to
...and then the results will print to the console. All specs run except those that expect a browser (the specs in `spec/html` are ignored).
The easiest way to run the tests in **Internet Explorer** is to run a VM that has IE installed. It's easy to do this with VirtualBox.
1. Download and install [VirtualBox](https://www.virtualbox.org/wiki/Downloads).
1. Download a VM image [from Microsoft](https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/). Select "VirtualBox" as the platform.
1. Unzip the downloaded archive. There should be an OVA file inside.
1. In VirtualBox, choose `File > Import Appliance` and select the OVA file. Accept the default settings in the dialog that appears. Now you have a Windows VM!
1. Run the VM and start IE.
1. With `bundle exec rake jasmine` running on your host machine, navigate to `http://10.0.2.2:8888` in IE.
## Before Committing or Submitting a Pull Request
1. Ensure all specs are green in browser *and* node

17
.github/ISSUE_TEMPLATE.md vendored Normal file
View File

@@ -0,0 +1,17 @@
### Are you creating an issue in the correct repository?
- When in doubt, create an issue here.
- If you have an issue with the Jasmine docs, file an issue in the docs repo
here: https://github.com/jasmine/jasmine.github.io
- This repository is for the core Jasmine framework
- If you are using a test runner that wraps Jasmine (Jasmine npm, karma, etc),
consider filing an issue with that library if appropriate
### When submitting an issue, please answer the following:
- What version are you using?
- What environment are you running Jasmine in (node, browser, etc)?
- How are you running Jasmine (standalone, npm, karma, etc)?
- If possible, include an example spec that demonstrates your issue.
Thanks for using Jasmine!

1
.gitignore vendored
View File

@@ -22,3 +22,4 @@ build/
*.egg-info/
dist
nbproject/
*.iml

View File

@@ -1,8 +1,8 @@
language: ruby
cache: bundler
sudo: false
rvm: 2.2.0
rvm: 2.2.2
script: $TEST_COMMAND

View File

@@ -1,4 +1,4 @@
Copyright (c) 2008-2014 Pivotal Labs
Copyright (c) 2008-2017 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -9,14 +9,14 @@
Jasmine is a Behavior Driven Development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework. Thus it's suited for websites, [Node.js](http://nodejs.org) projects, or anywhere that JavaScript can run.
Documentation & guides live here: [http://jasmine.github.io](http://jasmine.github.io/)
For a quick start guide of Jasmine 2.0, see the beginning of [http://jasmine.github.io/2.0/introduction.html](http://jasmine.github.io/2.0/introduction.html)
Documentation & guides live here: [http://jasmine.github.io](http://jasmine.github.io/)
For a quick start guide of Jasmine 2.x, see the beginning of [http://jasmine.github.io/edge/introduction.html](http://jasmine.github.io/edge/introduction.html)
Upgrading from Jasmine 1.x? Check out the [2.0 release notes](https://github.com/jasmine/jasmine/blob/v2.0.0/release_notes/20.md) for a list of what's new (including breaking interface changes). You can also read the [upgrade guide](http://jasmine.github.io/2.0/upgrading.html).
## Contributing
Please read the [contributors' guide](https://github.com/jasmine/jasmine/blob/master/CONTRIBUTING.md)
Please read the [contributors' guide](https://github.com/jasmine/jasmine/blob/master/.github/CONTRIBUTING.md)
## Installation
@@ -29,23 +29,26 @@ For the Jasmine Ruby Gem:<br>
For the Jasmine Python Egg:<br>
[https://github.com/jasmine/jasmine-py](https://github.com/jasmine/jasmine-py)
To install Jasmine standalone on your local box:
For the Jasmine headless browser gulp plugin:<br>
[https://github.com/jasmine/gulp-jasmine-browser](https://github.com/jasmine/gulp-jasmine-browser)
To install Jasmine standalone on your local box (where **_{#.#.#}_** below is substituted by the release number downloaded):
* Download the standalone distribution for your desired release from the [releases page](https://github.com/jasmine/jasmine/releases)
* Create a Jasmine directory in your project - `mkdir my-project/jasmine`
* Move the dist to your project directory - `mv jasmine/dist/jasmine-standalone-2.0.0.zip my-project/jasmine`
* Move the dist to your project directory - `mv jasmine/dist/jasmine-standalone-{#.#.#}.zip my-project/jasmine`
* Change directory - `cd my-project/jasmine`
* Unzip the dist - `unzip jasmine-standalone-2.0.0.zip`
* Unzip the dist - `unzip jasmine-standalone-{#.#.#}.zip`
Add the following to your HTML file:
```html
<link rel="shortcut icon" type="image/png" href="jasmine/lib/jasmine-2.0.0/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="jasmine/lib/jasmine-2.0.0/jasmine.css">
<link rel="shortcut icon" type="image/png" href="jasmine/lib/jasmine-core/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="jasmine/lib/jasmine-core/jasmine.css">
<script type="text/javascript" src="jasmine/lib/jasmine-2.0.0/jasmine.js"></script>
<script type="text/javascript" src="jasmine/lib/jasmine-2.0.0/jasmine-html.js"></script>
<script type="text/javascript" src="jasmine/lib/jasmine-2.0.0/boot.js"></script>
<script type="text/javascript" src="jasmine/lib/jasmine-core/jasmine.js"></script>
<script type="text/javascript" src="jasmine/lib/jasmine-core/jasmine-html.js"></script>
<script type="text/javascript" src="jasmine/lib/jasmine-core/boot.js"></script>
```
## Supported environments
@@ -62,15 +65,15 @@ Jasmine tests itself across many browsers (Safari, Chrome, Firefox, PhantomJS, a
## Maintainers
* [Davis W. Frank](mailto:dwfrank@pivotal.io), Pivotal Labs
* [Rajan Agaskar](mailto:rajan@pivotal.io), Pivotal Labs
* [Gregg Van Hove](mailto:gvanhove@pivotal.io), Pivotal Labs
* [Greg Cobb](mailto:gcobb@pivotal.io), Pivotal Labs
* [Chris Amavisca](mailto:camavisca@pivotal.io), Pivotal Labs
### Maintainers Emeritus
* [Davis W. Frank](mailto:dwfrank@pivotal.io), Pivotal Labs
* [Rajan Agaskar](mailto:rajan@pivotal.io), Pivotal Labs
* [Greg Cobb](mailto:gcobb@pivotal.io), Pivotal Labs
* [Chris Amavisca](mailto:camavisca@pivotal.io), Pivotal Labs
* [Christian Williams](mailto:antixian666@gmail.com), Cloud Foundry
* Sheel Choksi
Copyright (c) 2008-2015 Pivotal Labs. This software is licensed under the MIT License.
Copyright (c) 2008-2017 Pivotal Labs. This software is licensed under the MIT License.

View File

@@ -5,6 +5,7 @@ module.exports = {
sassDir: 'src/html',
outputStyle: 'compact',
noLineComments: true,
bundleExec: true
}
}
};

View File

@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
s.name = "jasmine-core"
s.version = Jasmine::Core::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Rajan Agaskar", "Davis W. Frank", "Gregg Van Hove"]
s.authors = ["Gregg Van Hove"]
s.summary = %q{JavaScript BDD framework}
s.description = %q{Test your JavaScript without any framework dependencies, in any environment, and with a nice descriptive syntax.}
s.email = %q{jasmine-js@googlegroups.com}

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2015 Pivotal Labs
Copyright (c) 2008-2017 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2015 Pivotal Labs
Copyright (c) 2008-2017 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -71,6 +71,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
getWindowLocation: function() { return window.location; }
});
var filterSpecs = !!queryString.getParam("spec");
var catchingExceptions = queryString.getParam("catch");
env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
@@ -98,7 +100,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
getContainer: function() { return document.body; },
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
timer: new jasmine.Timer()
timer: new jasmine.Timer(),
filterSpecs: filterSpecs
});
/**

View File

@@ -49,6 +49,8 @@
getWindowLocation: function() { return window.location; }
});
var filterSpecs = !!queryString.getParam("spec");
var catchingExceptions = queryString.getParam("catch");
env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
@@ -76,7 +78,8 @@
getContainer: function() { return document.body; },
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
timer: new jasmine.Timer()
timer: new jasmine.Timer(),
filterSpecs: filterSpecs
});
/**

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2015 Pivotal Labs
Copyright (c) 2008-2017 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -43,6 +43,7 @@ jasmineRequire.HtmlReporter = function(j$) {
onThrowExpectationsClick = options.onThrowExpectationsClick || function() {},
onRandomClick = options.onRandomClick || function() {},
addToExistingQueryString = options.addToExistingQueryString || defaultQueryString,
filterSpecs = options.filterSpecs,
timer = options.timer || noopTimer,
results = [],
specsExecuted = 0,
@@ -209,9 +210,10 @@ jasmineRequire.HtmlReporter = function(j$) {
if (specsExecuted < totalSpecsDefined) {
var skippedMessage = 'Ran ' + specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all';
var skippedLink = order && order.random ? '?random=true' : '?';
alert.appendChild(
createDom('span', {className: 'jasmine-bar jasmine-skipped'},
createDom('a', {href: '?', title: 'Run all specs'}, skippedMessage)
createDom('a', {href: skippedLink, title: 'Run all specs'}, skippedMessage)
)
);
}
@@ -237,15 +239,22 @@ jasmineRequire.HtmlReporter = function(j$) {
alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage, seedBar));
for(i = 0; i < failedSuites.length; i++) {
var errorBarClassName = 'jasmine-bar jasmine-errored';
var errorBarMessagePrefix = 'AfterAll ';
for(var i = 0; i < failedSuites.length; i++) {
var failedSuite = failedSuites[i];
for(var j = 0; j < failedSuite.failedExpectations.length; j++) {
var errorBarMessage = 'AfterAll ' + failedSuite.failedExpectations[j].message;
var errorBarClassName = 'jasmine-bar jasmine-errored';
alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessage));
alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessagePrefix + failedSuite.failedExpectations[j].message));
}
}
var globalFailures = (doneResult && doneResult.failedExpectations) || [];
for(i = 0; i < globalFailures.length; i++) {
var failure = globalFailures[i];
alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessagePrefix + failure.message));
}
var results = find('.jasmine-results');
results.appendChild(summary);
@@ -255,6 +264,9 @@ jasmineRequire.HtmlReporter = function(j$) {
var specListNode;
for (var i = 0; i < resultsTree.children.length; i++) {
var resultNode = resultsTree.children[i];
if (filterSpecs && !hasActiveSpec(resultNode)) {
continue;
}
if (resultNode.type == 'suite') {
var suiteListNode = createDom('ul', {className: 'jasmine-suite', id: 'suite-' + resultNode.result.id},
createDom('li', {className: 'jasmine-suite-detail'},
@@ -309,7 +321,7 @@ jasmineRequire.HtmlReporter = function(j$) {
setMenuModeTo('jasmine-failure-list');
var failureNode = find('.jasmine-failures');
for (var i = 0; i < failures.length; i++) {
for (i = 0; i < failures.length; i++) {
failureNode.appendChild(failures[i]);
}
}
@@ -382,6 +394,20 @@ jasmineRequire.HtmlReporter = function(j$) {
return (result.failedExpectations.length + result.passedExpectations.length) === 0 &&
result.status === 'passed';
}
function hasActiveSpec(resultNode) {
if (resultNode.type == 'spec' && resultNode.result.status != 'disabled') {
return true;
}
if (resultNode.type == 'suite') {
for (var i = 0, j = resultNode.children.length; i < j; i++) {
if (hasActiveSpec(resultNode.children[i])) {
return true;
}
}
}
}
}
return HtmlReporter;

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2008-2015 Pivotal Labs
Copyright (c) 2008-2017 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@@ -4,6 +4,6 @@
#
module Jasmine
module Core
VERSION = "2.4.0"
VERSION = "2.6.1"
end
end

View File

@@ -1,7 +1,7 @@
{
"name": "jasmine-core",
"license": "MIT",
"version": "2.4.0",
"version": "2.6.1",
"repository": {
"type": "git",
"url": "https://github.com/jasmine/jasmine.git"
@@ -13,22 +13,22 @@
"bdd"
],
"scripts": {
"test": "./node_modules/.bin/grunt jshint execSpecsInNode"
"test": "grunt jshint execSpecsInNode"
},
"description": "Official packaging of Jasmine's core files for use by Node.js projects.",
"homepage": "http://jasmine.github.io",
"main": "./lib/jasmine-core.js",
"devDependencies": {
"glob": "~5.0.13",
"grunt": "~0.4.1",
"grunt-cli": "^0.1.13",
"grunt-contrib-compass": "~0.6.0",
"grunt-contrib-compress": "~0.5.2",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-jshint": "~0.7.0",
"jasmine": "git://github.com/jasmine/jasmine-npm.git",
"glob": "~7.0.5",
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"grunt-contrib-compass": "^1.1.1",
"grunt-contrib-compress": "^1.3.0",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-jshint": "^1.0.0",
"jasmine": "^2.5.0",
"load-grunt-tasks": "^0.4.0",
"shelljs": "~0.1.4",
"shelljs": "^0.7.0",
"temp": "~0.8.1"
}
}

11
release_notes/2.4.1.md Normal file
View File

@@ -0,0 +1,11 @@
# Jasmine Core 2.4.1 Release Notes
## Changes
* Run `afterEach` in reverse order declared as before
- Reverts [#908](https://github.com/jasmine/jasmine/issues/908)
------
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_

116
release_notes/2.5.0.md Normal file
View File

@@ -0,0 +1,116 @@
# Jasmine 2.5.0 Release Notes
## Summary
This release contains a number of fixes and pull requests.
## Changes
* Rename `j$` to `jasmineUnderTest` for specs
- Please update any pull requests to simplify merging, thanks.
## Pull Requests & Issues
* Prettyprint objects whose constructors have custom toString method
- Fixes [#1019](https://github.com/jasmine/jasmine/issues/1019)
- Merges [#1099](https://github.com/jasmine/jasmine/issues/1099) from @mbildner
* Add gulp-jasmine-browser link to readme
- Fixes [#1089](https://github.com/jasmine/jasmine/issues/1089)
* Exclude lib directory from codeclimate
- Fixes [#1171](https://github.com/jasmine/jasmine/issues/1171)
* Add instructions for testing in IE
- Merges [#1170](https://github.com/jasmine/jasmine/issues/1170) from @benchristel
* Update devDependencies and fix issues from this
- Merges [#1162](https://github.com/jasmine/jasmine/issues/1162) from @amavisca
* Remove runnableLookupTable which is no longer used
- Merges [#1129](https://github.com/jasmine/jasmine/issues/1129) from @gregeninfrank
* Make `toEqual` pass for arrays with equivalent properties
- Merges [#1155](https://github.com/jasmine/jasmine/issues/1155) from @benchristel
* Update ruby version on travis to let rack install
- Merges [#1152](https://github.com/jasmine/jasmine/issues/1152) from @amavisca
* Fix jasmine setup in Electron environment
- Merges [#1079](https://github.com/jasmine/jasmine/issues/1079) from @skupr
- Fixes [#964](https://github.com/jasmine/jasmine/issues/964)
* Improve errors with the domain and how to use the API
- Merges [#1026](https://github.com/jasmine/jasmine/issues/1026) from @dhoko
- Fixes [#1025](https://github.com/jasmine/jasmine/issues/1025)
* The done function now returns null
- Merges [#1062](https://github.com/jasmine/jasmine/issues/1062) from @marneborn
- Fixes [#992](https://github.com/jasmine/jasmine/issues/992)
* Add .editorconfig file
- Merges [#1058](https://github.com/jasmine/jasmine/issues/1058) from @kapke
- Fixes [#1057](https://github.com/jasmine/jasmine/issues/1057)
* Improve error message when passing a non-function to callFake
- Merges [#1059](https://github.com/jasmine/jasmine/issues/1059) from @kapke
- Fixes [#1016](https://github.com/jasmine/jasmine/issues/1016)
* Allow expectations in a global beforeAll or afterAll
- Fixes [#811](https://github.com/jasmine/jasmine/issues/811)
* Correctly tear down spies on inherited methods
- Merges [#1036](https://github.com/jasmine/jasmine/issues/1036) from @benchristel
- Fixes [#737](https://github.com/jasmine/jasmine/issues/737)
* Array equality treats undefined elements as equal however they got in there
- Fixes [#786](https://github.com/jasmine/jasmine/issues/786)
* Add support for a fallback reporter
- Merges [#1009](https://github.com/jasmine/jasmine/issues/1009) from @mauricioborges
* Grunt task for compass should prefix command with 'bundle exec'
- Merges [#1047](https://github.com/jasmine/jasmine/issues/1047) from @d-reinhold
* Fix `toEqual` for Microsoft Edge
- Merges [#1041](https://github.com/jasmine/jasmine/issues/1041) from @everedifice
* Update describe error message to no longer assume errant args are `done`
- Fixes [#896](https://github.com/jasmine/jasmine/issues/896)
* Add toBeGreatThanOrEqual and toBeLessThanOrEqual matchers
- Merges [#1049](https://github.com/jasmine/jasmine/issues/1049) from @rullopat
- Fixes [#1013](https://github.com/jasmine/jasmine/issues/1013)
* Support call count of 0 with toHaveBeenCalledTimes matcher
- Merges [#1048](https://github.com/jasmine/jasmine/issues/1048) from @logankd
- Fixes [#994](https://github.com/jasmine/jasmine/issues/994)
* Correctly clean up spies after a spy is replaced and re-spied upon
- Merges [#1011](https://github.com/jasmine/jasmine/issues/1011) from @bodawei
- Fixes [#1010](https://github.com/jasmine/jasmine/issues/1010)
* remove extra topSuite `queueRunner` construction parameter
- Merges [#1006](https://github.com/jasmine/jasmine/issues/1006) from @jurko-gospodnetic
* add option to shallow clone args in call tracker
- Merges [#1000](https://github.com/jasmine/jasmine/issues/1000) from @a-r-d
- Fixes [#872](https://github.com/jasmine/jasmine/issues/872)
* Update license year range to 2016
- Merges [#1021](https://github.com/jasmine/jasmine/issues/1021) from pra85
* Persist randomize param in 'run all' links
- Merges [#990](https://github.com/jasmine/jasmine/issues/990) from @basawyer
* make DelayedFunctionScheduler update the mockDate
- Fixes [#915](https://github.com/jasmine/jasmine/issues/915)
- Merges [#980](https://github.com/jasmine/jasmine/issues/980) from @andrewiggings
* Allow `spyOn` to allow a respy for functions that have already been spied upon
- Merges [#953](https://github.com/jasmine/jasmine/issues/953) from @guy-mograbi-at-gigaspaces
- Fixes [#931](https://github.com/jasmine/jasmine/issues/931)
------
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_

19
release_notes/2.5.1.md Normal file
View File

@@ -0,0 +1,19 @@
# Jasmine 2.5.1 Release Notes
## Pull Requests & Issues
* fallback on assignment when a spy cannot be deleted
- Merges [#1193](https://github.com/jasmine/jasmine/issues/1193) from @seanparmlee
- Fixes [#1189](https://github.com/jasmine/jasmine/issues/1189)
* Fix issue with equality of Arrays in PhantomJS
- Merges [#1192](https://github.com/jasmine/jasmine/issues/1192) from @logankd
- Fixes [#1188](https://github.com/jasmine/jasmine/issues/1188)
* Properly tick date along with clock
- Fixes [#1190](https://github.com/jasmine/jasmine/issues/1190)
------
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_

14
release_notes/2.5.2.md Normal file
View File

@@ -0,0 +1,14 @@
# Jasmine 2.5.2 Release Notes
## Pull Requests & Issues
* Allow currently registered reporters to be cleared
- [jasmine/jasmine-npm#88](https://github.com/jasmine/jasmine-npm/issues/88)
* Use `isFunction` to check for functionness in `callFake`
- Fixes [#1191](https://github.com/jasmine/jasmine/issues/1191)
------
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_

108
release_notes/2.6.0.md Normal file
View File

@@ -0,0 +1,108 @@
# Jasmine 2.6.0 Release Notes
## Summary
This release contains a number of fixes and pull requests.
## Pull Requests & Issues
Updating introduction url to last version
- Merges [#1316](https://github.com/jasmine/jasmine/issues/1316) from @rachelcarmena
* Throw a recognizable Error message when `fail` outside of a spec.
- Fixes [#1017](https://github.com/jasmine/jasmine/issues/1017)
* Allow the matcher provide a custom error message
- Merges [#1298](https://github.com/jasmine/jasmine/issues/1298) from @deckar01
- Fixes [#1123](https://github.com/jasmine/jasmine/issues/1123)
* Fix the order in which afterAll hooks are run to match afterEach
- Merges [#1312](https://github.com/jasmine/jasmine/issues/1312) from @gdborton
- Fixes [#1311](https://github.com/jasmine/jasmine/issues/1311)
* Add matchers for positive and negative infinity
- Merges [#1300](https://github.com/jasmine/jasmine/issues/1300) from @toubou91
- Fixes [#1294](https://github.com/jasmine/jasmine/issues/1294)
* Add a first pass at JSDocs for the intended public API
- Fixes [#596](https://github.com/jasmine/jasmine/issues/596)
* Pretty print objects passed to fail method
- Merges [#1283](https://github.com/jasmine/jasmine/issues/1283) from @mmmichl
- Fixes [#1090](https://github.com/jasmine/jasmine/issues/1090)
* Properly check for Error constructor from a different frame
- Merges [#1275](https://github.com/jasmine/jasmine/issues/1275) from @anseki
- Fixes [#1252](https://github.com/jasmine/jasmine/issues/1252)
* Add toHaveBeenCalledBefore matcher
- Merges [#1242](https://github.com/jasmine/jasmine/issues/1242) from @DamienCassou
* Collect unhandled exceptions and pass them to the current runnable
- Fixes [#529](https://github.com/jasmine/jasmine/issues/529)
- Fixes [#937](https://github.com/jasmine/jasmine/issues/937)
* Nicer error messages for `spyOn` when `null` is provided
- Fixes [#1258](https://github.com/jasmine/jasmine/issues/1258)
* Require arguments to beforeEach, it, etc, to be actual functions
- Merges [#1222](https://github.com/jasmine/jasmine/issues/1222) from @voithos
- Fixes [#1004](https://github.com/jasmine/jasmine/issues/1004)
* Update MIT.LICENSE for new year
- Merges [#1249](https://github.com/jasmine/jasmine/issues/1249) from @Scottkao85
* Update README.md for new year
- Merges [#1248](https://github.com/jasmine/jasmine/issues/1248) from @Nebojsaa
* Remove unused `message` param from Suite#pend
- See [#1132](https://github.com/jasmine/jasmine/issues/1132)
* Fix bug where before/afterAll were being executed in disabled suites.
- Merges [#1225](https://github.com/jasmine/jasmine/issues/1225) from @voithos
- Fixes [#1175](https://github.com/jasmine/jasmine/issues/1175)
* Make toEqual matcher report the difference between objects
- Merges [#1163](https://github.com/jasmine/jasmine/issues/1163) from @benchristel
- Fixes [#675](https://github.com/jasmine/jasmine/issues/675)
- Merges [#1236](https://github.com/jasmine/jasmine/issues/1236) from @benchristel
* Implement spies for get/set functions on accessor properties
- Merges [#1203](https://github.com/jasmine/jasmine/issues/1203) from @celluj34
- Merges [#1008](https://github.com/jasmine/jasmine/issues/1008) from @smacker
- Fixes [#943](https://github.com/jasmine/jasmine/issues/943)
* When the HtmlReporter has a 'spec' query param, the spec list only shows matching specs/suites
- Merges [#1046](https://github.com/jasmine/jasmine/issues/1046) from @d-reinhold
- Fixes [#510](https://github.com/jasmine/jasmine/issues/510)
* createSpyObj may use object for method/response shorthand
- Merges [#1101](https://github.com/jasmine/jasmine/issues/1101) from @mbildner
* Separate clear stack and run it after each spec
- Fixes [#985](https://github.com/jasmine/jasmine/issues/985)
- Fixes [#945](https://github.com/jasmine/jasmine/issues/945)
- Fixes [#366](https://github.com/jasmine/jasmine/issues/366)
* Now spies preserve original function arity
- Merges [#1055](https://github.com/jasmine/jasmine/issues/1055) from @kapke
- Fixes [#991](https://github.com/jasmine/jasmine/issues/991)
* Added support for ES6 sets to toContain and toEqual.
- Merges [#1067](https://github.com/jasmine/jasmine/issues/1067) from @alur
* Correctly pretty print objects from other contexts (e.g. iframes) and which do not override toString
- Merges [#1091](https://github.com/jasmine/jasmine/issues/1091) from @thatfulvioguy
- Fixes [#1087](https://github.com/jasmine/jasmine/issues/1087)
* Pass custom testers to asymmetric testers
- Merges [#1139](https://github.com/jasmine/jasmine/issues/1139) from @joeyparrish
- Fixes [#1138](https://github.com/jasmine/jasmine/issues/1138)
* Fix bad url in README
- Merges [#1215](https://github.com/jasmine/jasmine/issues/1215) from @mattc41190
------
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_

31
release_notes/2.6.1.md Normal file
View File

@@ -0,0 +1,31 @@
# Jasmine 2.6.1 Release Notes
## Summary
This is a patch release to fix some regressions in the 2.6.0 release
## Pull Requests & Issues
* Update README.md to make installation instructions more version-agnostic
- Merges #1319 from @reinrl
* Check for `process.listeners` as well, for GlobalErrors
- Fixes #1333
* allow explicit undefined as function for `it` and `xit`
- Merges #1329 from @UziTech
- Fixes #1328
* remove eval to create spy wrapper
- Merges #1330 from @UziTech
- Fixes #1325
* iterate through keys with a regular for loop
- Merges #1326 from @seanparmelee
- Fixes #1321
- Fixes #1324
------
_Release Notes generated with _[Anchorman](http://github.com/infews/anchorman)_

View File

@@ -19,7 +19,7 @@ describe("ConsoleReporter", function() {
});
it("reports that the suite has started to the console", function() {
var reporter = new j$.ConsoleReporter({
var reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print
});
@@ -30,7 +30,7 @@ describe("ConsoleReporter", function() {
it("starts the provided timer when jasmine starts", function() {
var timerSpy = jasmine.createSpyObj('timer', ['start']),
reporter = new j$.ConsoleReporter({
reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print,
timer: timerSpy
});
@@ -41,7 +41,7 @@ describe("ConsoleReporter", function() {
});
it("reports a passing spec as a dot", function() {
var reporter = new j$.ConsoleReporter({
var reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print
});
@@ -51,7 +51,7 @@ describe("ConsoleReporter", function() {
});
it("does not report a disabled spec", function() {
var reporter = new j$.ConsoleReporter({
var reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print
});
@@ -61,7 +61,7 @@ describe("ConsoleReporter", function() {
});
it("reports a failing spec as an 'F'", function() {
var reporter = new j$.ConsoleReporter({
var reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print
});
@@ -71,7 +71,7 @@ describe("ConsoleReporter", function() {
});
it("reports a pending spec as a '*'", function() {
var reporter = new j$.ConsoleReporter({
var reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print
});
@@ -81,7 +81,7 @@ describe("ConsoleReporter", function() {
});
it("alerts user if there are no specs", function(){
var reporter = new j$.ConsoleReporter({
var reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print
});
@@ -94,7 +94,7 @@ describe("ConsoleReporter", function() {
it("reports a summary when done (singular spec and time)", function() {
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
reporter = new j$.ConsoleReporter({
reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print,
timer: timerSpy
});
@@ -114,7 +114,7 @@ describe("ConsoleReporter", function() {
it("reports a summary when done (pluralized specs and seconds)", function() {
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
reporter = new j$.ConsoleReporter({
reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print,
timer: timerSpy
});
@@ -148,7 +148,7 @@ describe("ConsoleReporter", function() {
});
it("reports a summary when done that includes stack traces for a failing suite", function() {
var reporter = new j$.ConsoleReporter({
var reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print
});
@@ -182,7 +182,7 @@ describe("ConsoleReporter", function() {
beforeEach(function() {
onComplete = jasmine.createSpy('onComplete');
reporter = new j$.ConsoleReporter({
reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print,
onComplete: onComplete
});
@@ -210,7 +210,7 @@ describe("ConsoleReporter", function() {
describe("with color", function() {
it("reports that the suite has started to the console", function() {
var reporter = new j$.ConsoleReporter({
var reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print,
showColors: true
});
@@ -221,7 +221,7 @@ describe("ConsoleReporter", function() {
});
it("reports a passing spec as a dot", function() {
var reporter = new j$.ConsoleReporter({
var reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print,
showColors: true
});
@@ -232,7 +232,7 @@ describe("ConsoleReporter", function() {
});
it("does not report a disabled spec", function() {
var reporter = new j$.ConsoleReporter({
var reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print,
showColors: true
});
@@ -243,7 +243,7 @@ describe("ConsoleReporter", function() {
});
it("reports a failing spec as an 'F'", function() {
var reporter = new j$.ConsoleReporter({
var reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print,
showColors: true
});
@@ -254,7 +254,7 @@ describe("ConsoleReporter", function() {
});
it("displays all afterAll exceptions", function() {
var reporter = new j$.ConsoleReporter({
var reporter = new jasmineUnderTest.ConsoleReporter({
print: out.print,
showColors: true
});

View File

@@ -1,6 +1,6 @@
describe("CallTracker", function() {
it("tracks that it was called when executed", function() {
var callTracker = new j$.CallTracker();
var callTracker = new jasmineUnderTest.CallTracker();
expect(callTracker.any()).toBe(false);
@@ -10,7 +10,7 @@ describe("CallTracker", function() {
});
it("tracks that number of times that it is executed", function() {
var callTracker = new j$.CallTracker();
var callTracker = new jasmineUnderTest.CallTracker();
expect(callTracker.count()).toEqual(0);
@@ -20,7 +20,7 @@ describe("CallTracker", function() {
});
it("tracks the params from each execution", function() {
var callTracker = new j$.CallTracker();
var callTracker = new jasmineUnderTest.CallTracker();
callTracker.track({object: void 0, args: []});
callTracker.track({object: {}, args: [0, "foo"]});
@@ -31,13 +31,13 @@ describe("CallTracker", function() {
});
it("returns any empty array when there was no call", function() {
var callTracker = new j$.CallTracker();
var callTracker = new jasmineUnderTest.CallTracker();
expect(callTracker.argsFor(0)).toEqual([]);
});
it("allows access for the arguments for all calls", function() {
var callTracker = new j$.CallTracker();
var callTracker = new jasmineUnderTest.CallTracker();
callTracker.track({object: {}, args: []});
callTracker.track({object: {}, args: [0, "foo"]});
@@ -46,7 +46,7 @@ describe("CallTracker", function() {
});
it("tracks the context and arguments for each call", function() {
var callTracker = new j$.CallTracker();
var callTracker = new jasmineUnderTest.CallTracker();
callTracker.track({object: {}, args: []});
callTracker.track({object: {}, args: [0, "foo"]});
@@ -57,7 +57,7 @@ describe("CallTracker", function() {
});
it("simplifies access to the arguments for the last (most recent) call", function() {
var callTracker = new j$.CallTracker();
var callTracker = new jasmineUnderTest.CallTracker();
callTracker.track();
callTracker.track({object: {}, args: [0, "foo"]});
@@ -69,13 +69,13 @@ describe("CallTracker", function() {
});
it("returns a useful falsy value when there isn't a last (most recent) call", function() {
var callTracker = new j$.CallTracker();
var callTracker = new jasmineUnderTest.CallTracker();
expect(callTracker.mostRecent()).toBeFalsy();
});
it("simplifies access to the arguments for the first (oldest) call", function() {
var callTracker = new j$.CallTracker();
var callTracker = new jasmineUnderTest.CallTracker();
callTracker.track({object: {}, args: [0, "foo"]});
@@ -83,14 +83,14 @@ describe("CallTracker", function() {
});
it("returns a useful falsy value when there isn't a first (oldest) call", function() {
var callTracker = new j$.CallTracker();
var callTracker = new jasmineUnderTest.CallTracker();
expect(callTracker.first()).toBeFalsy();
});
it("allows the tracking to be reset", function() {
var callTracker = new j$.CallTracker();
var callTracker = new jasmineUnderTest.CallTracker();
callTracker.track();
callTracker.track({object: {}, args: [0, "foo"]});
@@ -102,4 +102,19 @@ describe("CallTracker", function() {
expect(callTracker.all()).toEqual([]);
expect(callTracker.mostRecent()).toBeFalsy();
});
it("allows object arguments to be shallow cloned", function() {
var callTracker = new jasmineUnderTest.CallTracker();
callTracker.saveArgumentsByValue();
var objectArg = {"foo": "bar"},
arrayArg = ["foo", "bar"];
callTracker.track({object: {}, args: [objectArg, arrayArg, false, undefined, null, NaN, "", 0, 1.0]});
expect(callTracker.mostRecent().args[0]).not.toBe(objectArg);
expect(callTracker.mostRecent().args[0]).toEqual(objectArg);
expect(callTracker.mostRecent().args[1]).not.toBe(arrayArg);
expect(callTracker.mostRecent().args[1]).toEqual(arrayArg);
});
});

View File

@@ -0,0 +1,53 @@
describe("ClearStack", function() {
it("works in an integrationy way", function(done) {
var clearStack = jasmineUnderTest.getClearStack(jasmineUnderTest.getGlobal());
clearStack(function() {
done();
});
});
it("uses setImmediate when available", function() {
var setImmediate = jasmine.createSpy('setImmediate').and.callFake(function(fn) { fn() }),
global = { setImmediate: setImmediate },
clearStack = jasmineUnderTest.getClearStack(global),
called = false;
clearStack(function() {
called = true;
});
expect(called).toBe(true);
expect(setImmediate).toHaveBeenCalled();
});
it("uses MessageChannels when available", function() {
var fakeChannel = {
port1: {},
port2: { postMessage: function() { fakeChannel.port1.onmessage(); } }
},
global = { MessageChannel: function() { return fakeChannel; } },
clearStack = jasmineUnderTest.getClearStack(global),
called = false;
clearStack(function() {
called = true;
});
expect(called).toBe(true);
});
it("falls back to setTimeout", function() {
var setTimeout = jasmine.createSpy('setTimeout').and.callFake(function(fn) { fn() }),
global = { setTimeout: setTimeout },
clearStack = jasmineUnderTest.getClearStack(global),
called = false;
clearStack(function() {
called = true;
});
expect(called).toBe(true);
expect(setTimeout).toHaveBeenCalledWith(jasmine.any(Function), 0);
});
});

View File

@@ -6,7 +6,7 @@ describe("Clock", function() {
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction"]),
delayedFn = jasmine.createSpy("delayedFn"),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
fakeGlobal.setTimeout(delayedFn, 0);
@@ -28,7 +28,7 @@ describe("Clock", function() {
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["removeFunctionWithId"]),
delayedFn = jasmine.createSpy("delayedFn"),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
fakeGlobal.clearTimeout("foo");
@@ -50,7 +50,7 @@ describe("Clock", function() {
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction"]),
delayedFn = jasmine.createSpy("delayedFn"),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
fakeGlobal.setInterval(delayedFn, 0);
@@ -72,7 +72,7 @@ describe("Clock", function() {
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["removeFunctionWithId"]),
delayedFn = jasmine.createSpy("delayedFn"),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
fakeGlobal.clearInterval("foo");
@@ -94,7 +94,7 @@ describe("Clock", function() {
fakeGlobal = { setTimeout: originalFakeSetTimeout },
delayedFunctionSchedulerFactory = jasmine.createSpy('delayedFunctionSchedulerFactory'),
mockDate = {},
clock = new j$.Clock(fakeGlobal, delayedFunctionSchedulerFactory, mockDate);
clock = new jasmineUnderTest.Clock(fakeGlobal, delayedFunctionSchedulerFactory, mockDate);
fakeGlobal.setTimeout = replacedSetTimeout;
@@ -112,7 +112,7 @@ describe("Clock", function() {
fakeGlobal = { clearTimeout: originalFakeClearTimeout },
delayedFunctionSchedulerFactory = jasmine.createSpy('delayedFunctionSchedulerFactory'),
mockDate = {},
clock = new j$.Clock(fakeGlobal, delayedFunctionSchedulerFactory, mockDate);
clock = new jasmineUnderTest.Clock(fakeGlobal, delayedFunctionSchedulerFactory, mockDate);
fakeGlobal.clearTimeout = replacedClearTimeout;
@@ -130,7 +130,7 @@ describe("Clock", function() {
fakeGlobal = { setInterval: originalFakeSetInterval },
delayedFunctionSchedulerFactory = jasmine.createSpy('delayedFunctionSchedulerFactory'),
mockDate = {},
clock = new j$.Clock(fakeGlobal, delayedFunctionSchedulerFactory, mockDate);
clock = new jasmineUnderTest.Clock(fakeGlobal, delayedFunctionSchedulerFactory, mockDate);
fakeGlobal.setInterval = replacedSetInterval;
@@ -148,7 +148,7 @@ describe("Clock", function() {
fakeGlobal = { clearInterval: originalFakeClearInterval },
delayedFunctionSchedulerFactory = jasmine.createSpy('delayedFunctionSchedulerFactory'),
mockDate = {},
clock = new j$.Clock(fakeGlobal, delayedFunctionSchedulerFactory, mockDate);
clock = new jasmineUnderTest.Clock(fakeGlobal, delayedFunctionSchedulerFactory, mockDate);
fakeGlobal.clearInterval = replacedClearInterval;
@@ -174,7 +174,7 @@ describe("Clock", function() {
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction", "reset"]),
delayedFn = jasmine.createSpy("delayedFn"),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock.install();
clock.uninstall();
@@ -204,7 +204,7 @@ describe("Clock", function() {
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction", "reset", "removeFunctionWithId"]),
delayedFn = jasmine.createSpy("delayedFn"),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
passedFunctionCalled = false;
clock.withMock(function() {
@@ -251,7 +251,7 @@ describe("Clock", function() {
delayedFunctionScheduler = jasmine.createSpyObj("delayedFunctionScheduler", ["scheduleFunction", "reset", "removeFunctionWithId"]),
delayedFn = jasmine.createSpy("delayedFn"),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
passedFunctionCalled = false;
expect(function() {
@@ -294,7 +294,7 @@ describe("Clock", function() {
fakeGlobal = { setTimeout: fakeSetTimeout },
delayedFn = jasmine.createSpy('delayedFn'),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock.install();
clock.setTimeout(delayedFn, 0, 'a', 'b');
@@ -311,7 +311,7 @@ describe("Clock", function() {
fakeGlobal = { setTimeout: fakeSetTimeout },
delayedFn = jasmine.createSpy('delayedFn'),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
timeoutId;
clock.install();
@@ -326,7 +326,7 @@ describe("Clock", function() {
fakeGlobal = { setTimeout: fakeClearTimeout },
delayedFn = jasmine.createSpy('delayedFn'),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock.install();
clock.clearTimeout(123);
@@ -342,7 +342,7 @@ describe("Clock", function() {
fakeGlobal = { setInterval: fakeSetInterval },
delayedFn = jasmine.createSpy('delayedFn'),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock.install();
clock.setInterval(delayedFn, 0, 'a', 'b');
@@ -359,7 +359,7 @@ describe("Clock", function() {
fakeGlobal = { setInterval: fakeSetInterval },
delayedFn = jasmine.createSpy('delayedFn'),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate),
intervalId;
clock.install();
@@ -374,7 +374,7 @@ describe("Clock", function() {
fakeGlobal = { setInterval: clearInterval },
delayedFn = jasmine.createSpy('delayedFn'),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock.install();
clock.clearInterval(123);
@@ -384,7 +384,7 @@ describe("Clock", function() {
});
it("gives you a friendly reminder if the Clock is not installed and you tick", function() {
var clock = new j$.Clock({}, jasmine.createSpyObj('delayedFunctionScheduler', ['tick']));
var clock = new jasmineUnderTest.Clock({}, jasmine.createSpyObj('delayedFunctionScheduler', ['tick']));
expect(function() {
clock.tick(50);
}).toThrow();
@@ -401,7 +401,7 @@ describe("Clock", function() {
setInterval: fakeSetInterval
},
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock(fakeGlobal, function () { return delayedFunctionScheduler; }, mockDate);
fakeSetTimeout.apply = null;
fakeSetInterval.apply = null;
@@ -428,9 +428,9 @@ describe("Clock (acceptance)", function() {
delayedFn2 = jasmine.createSpy('delayedFn2'),
delayedFn3 = jasmine.createSpy('delayedFn3'),
recurring1 = jasmine.createSpy('recurring1'),
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate);
clock.install();
@@ -475,9 +475,9 @@ describe("Clock (acceptance)", function() {
it("can clear a previously set timeout", function() {
var clearedFn = jasmine.createSpy('clearedFn'),
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate),
clock = new jasmineUnderTest.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate),
timeoutId;
clock.install();
@@ -493,9 +493,9 @@ describe("Clock (acceptance)", function() {
it("can clear a previously set interval using that interval's handler", function() {
var spy = jasmine.createSpy('spy'),
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock({setInterval: function() {}}, function () { return delayedFunctionScheduler; }, mockDate),
clock = new jasmineUnderTest.Clock({setInterval: function() {}}, function () { return delayedFunctionScheduler; }, mockDate),
intervalId;
clock.install();
@@ -511,9 +511,9 @@ describe("Clock (acceptance)", function() {
it("correctly schedules functions after the Clock has advanced", function() {
var delayedFn1 = jasmine.createSpy('delayedFn1'),
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
clock.install();
@@ -528,9 +528,9 @@ describe("Clock (acceptance)", function() {
it("correctly schedules functions while the Clock is advancing", function() {
var delayedFn1 = jasmine.createSpy('delayedFn1'),
delayedFn2 = jasmine.createSpy('delayedFn2'),
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
delayedFn1.and.callFake(function() { clock.setTimeout(delayedFn2, 0); });
clock.install();
@@ -547,9 +547,9 @@ describe("Clock (acceptance)", function() {
it("correctly calls functions scheduled while the Clock is advancing", function() {
var delayedFn1 = jasmine.createSpy('delayedFn1'),
delayedFn2 = jasmine.createSpy('delayedFn2'),
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
delayedFn1.and.callFake(function() { clock.setTimeout(delayedFn2, 1); });
clock.install();
@@ -563,9 +563,9 @@ describe("Clock (acceptance)", function() {
it("correctly schedules functions scheduled while the Clock is advancing but after the Clock is uninstalled", function() {
var delayedFn1 = jasmine.createSpy('delayedFn1'),
delayedFn2 = jasmine.createSpy('delayedFn2'),
delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
mockDate = { install: function() {}, tick: function() {}, uninstall: function() {} },
clock = new j$.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
clock = new jasmineUnderTest.Clock({setTimeout: function() {}}, function () { return delayedFunctionScheduler; }, mockDate);
delayedFn1.and.callFake(function() {
clock.uninstall();
@@ -585,10 +585,10 @@ describe("Clock (acceptance)", function() {
});
it("does not mock the Date object by default", function() {
var delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
global = {Date: Date},
mockDate = new j$.MockDate(global),
clock = new j$.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate);
mockDate = new jasmineUnderTest.MockDate(global),
clock = new jasmineUnderTest.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate);
clock.install();
@@ -602,10 +602,10 @@ describe("Clock (acceptance)", function() {
});
it("mocks the Date object and sets it to current time", function() {
var delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
global = {Date: Date},
mockDate = new j$.MockDate(global),
clock = new j$.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate);
mockDate = new jasmineUnderTest.MockDate(global),
clock = new jasmineUnderTest.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate);
clock.install().mockDate();
@@ -626,10 +626,10 @@ describe("Clock (acceptance)", function() {
});
it("mocks the Date object and sets it to a given time", function() {
var delayedFunctionScheduler = new j$.DelayedFunctionScheduler(),
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
global = {Date: Date},
mockDate = new j$.MockDate(global),
clock = new j$.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate),
mockDate = new jasmineUnderTest.MockDate(global),
clock = new jasmineUnderTest.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate),
baseTime = new Date(2013, 9, 23);
@@ -652,4 +652,31 @@ describe("Clock (acceptance)", function() {
expect(timeoutDate).toEqual(baseTime.getTime() + 150);
});
it("mocks the Date object and updates the date per delayed function", function () {
var delayedFunctionScheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
global = {Date: Date},
mockDate = new jasmineUnderTest.MockDate(global),
clock = new jasmineUnderTest.Clock({setTimeout: setTimeout}, function () { return delayedFunctionScheduler; }, mockDate),
baseTime = new Date();
clock.install().mockDate(baseTime);
var actualTimes = [];
var pushCurrentTime = function() { actualTimes.push(global.Date().getTime()); };
delayedFunctionScheduler.scheduleFunction(pushCurrentTime);
delayedFunctionScheduler.scheduleFunction(pushCurrentTime, 1);
delayedFunctionScheduler.scheduleFunction(pushCurrentTime, 3);
clock.tick(1);
expect(global.Date().getTime()).toEqual(baseTime.getTime() + 1);
clock.tick(3);
expect(global.Date().getTime()).toEqual(baseTime.getTime() + 4);
clock.tick(1);
expect(global.Date().getTime()).toEqual(baseTime.getTime() + 5);
expect(actualTimes).toEqual([baseTime.getTime(), baseTime.getTime() + 1, baseTime.getTime() + 3]);
})
});

View File

@@ -1,6 +1,6 @@
describe("DelayedFunctionScheduler", function() {
it("schedules a function for later execution", function() {
var scheduler = new j$.DelayedFunctionScheduler(),
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn');
scheduler.scheduleFunction(fn, 0);
@@ -13,7 +13,7 @@ describe("DelayedFunctionScheduler", function() {
});
it("schedules a string for later execution", function() {
var scheduler = new j$.DelayedFunctionScheduler(),
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
strfn = "horrible = true;";
scheduler.scheduleFunction(strfn, 0);
@@ -24,7 +24,7 @@ describe("DelayedFunctionScheduler", function() {
});
it("#tick defaults to 0", function() {
var scheduler = new j$.DelayedFunctionScheduler(),
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn');
scheduler.scheduleFunction(fn, 0);
@@ -37,7 +37,7 @@ describe("DelayedFunctionScheduler", function() {
});
it("defaults delay to 0", function() {
var scheduler = new j$.DelayedFunctionScheduler(),
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn');
scheduler.scheduleFunction(fn);
@@ -50,7 +50,7 @@ describe("DelayedFunctionScheduler", function() {
});
it("optionally passes params to scheduled functions", function() {
var scheduler = new j$.DelayedFunctionScheduler(),
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn');
scheduler.scheduleFunction(fn, 0, ['foo', 'bar']);
@@ -63,7 +63,7 @@ describe("DelayedFunctionScheduler", function() {
});
it("scheduled fns can optionally reoccur", function() {
var scheduler = new j$.DelayedFunctionScheduler(),
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn');
scheduler.scheduleFunction(fn, 20, [], true);
@@ -85,7 +85,7 @@ describe("DelayedFunctionScheduler", function() {
});
it("increments scheduled fns ids unless one is passed", function() {
var scheduler = new j$.DelayedFunctionScheduler();
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler();
expect(scheduler.scheduleFunction(function() {
}, 0)).toBe(1);
@@ -98,7 +98,7 @@ describe("DelayedFunctionScheduler", function() {
});
it("#removeFunctionWithId removes a previously scheduled function with a given id", function() {
var scheduler = new j$.DelayedFunctionScheduler(),
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn'),
timeoutKey;
@@ -114,7 +114,7 @@ describe("DelayedFunctionScheduler", function() {
});
it("executes recurring functions interleaved with regular functions in the correct order", function() {
var scheduler = new j$.DelayedFunctionScheduler(),
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn'),
recurringCallCount = 0,
recurring = jasmine.createSpy('recurring').and.callFake(function() {
@@ -135,7 +135,7 @@ describe("DelayedFunctionScheduler", function() {
});
it("schedules a function for later execution during a tick", function () {
var scheduler = new j$.DelayedFunctionScheduler(),
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn'),
fnDelay = 10;
@@ -151,7 +151,7 @@ describe("DelayedFunctionScheduler", function() {
});
it("#removeFunctionWithId removes a previously scheduled function with a given id during a tick", function () {
var scheduler = new j$.DelayedFunctionScheduler(),
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn'),
fnDelay = 10,
timeoutKey;
@@ -169,7 +169,7 @@ describe("DelayedFunctionScheduler", function() {
});
it("executes recurring functions interleaved with regular functions and functions scheduled during a tick in the correct order", function () {
var scheduler = new j$.DelayedFunctionScheduler(),
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn'),
recurringCallCount = 0,
recurring = jasmine.createSpy('recurring').and.callFake(function() {
@@ -202,7 +202,7 @@ describe("DelayedFunctionScheduler", function() {
});
it("executes recurring functions after rescheduling them", function () {
var scheduler = new j$.DelayedFunctionScheduler(),
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
recurring = function() {
expect(scheduler.scheduleFunction).toHaveBeenCalled();
};
@@ -215,7 +215,7 @@ describe("DelayedFunctionScheduler", function() {
});
it("removes functions during a tick that runs the function", function() {
var scheduler = new j$.DelayedFunctionScheduler(),
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn'),
fnDelay = 10,
timeoutKey;
@@ -234,7 +234,7 @@ describe("DelayedFunctionScheduler", function() {
});
it("removes functions during the first tick that runs the function", function() {
var scheduler = new j$.DelayedFunctionScheduler(),
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
fn = jasmine.createSpy('fn'),
fnDelay = 10,
timeoutKey;
@@ -251,5 +251,18 @@ describe("DelayedFunctionScheduler", function() {
expect(fn).toHaveBeenCalled();
expect(fn.calls.count()).toBe(1);
});
it("updates the mockDate per scheduled time", function () {
var scheduler = new jasmineUnderTest.DelayedFunctionScheduler(),
tickDate = jasmine.createSpy('tickDate');
scheduler.scheduleFunction(function() {});
scheduler.scheduleFunction(function() {}, 1);
scheduler.tick(1, tickDate);
expect(tickDate).toHaveBeenCalledWith(0);
expect(tickDate).toHaveBeenCalledWith(1);
})
});

View File

@@ -2,20 +2,20 @@
describe("Env", function() {
var env;
beforeEach(function() {
env = new j$.Env();
env = new jasmineUnderTest.Env();
});
describe("#pending", function() {
it("throws the Pending Spec exception", function() {
expect(function() {
env.pending();
}).toThrow(j$.Spec.pendingSpecExceptionMessage);
}).toThrow(jasmineUnderTest.Spec.pendingSpecExceptionMessage);
});
it("throws the Pending Spec exception with a custom message", function() {
expect(function() {
env.pending('custom message');
}).toThrow(j$.Spec.pendingSpecExceptionMessage + 'custom message');
}).toThrow(jasmineUnderTest.Spec.pendingSpecExceptionMessage + 'custom message');
});
});
@@ -26,21 +26,12 @@ describe("Env", function() {
});
});
describe('#describe', function () {
var spec = function(done){};
it("throws the error", function() {
expect(function() {
env.describe('done method', spec);
}).toThrow(new Error('describe does not expect a done parameter'));
});
});
it('can configure specs to throw errors on expectation failures', function() {
env.throwOnExpectationFailure(true);
spyOn(j$, 'Spec');
spyOn(jasmineUnderTest, 'Spec');
env.it('foo', function() {});
expect(j$.Spec).toHaveBeenCalledWith(jasmine.objectContaining({
expect(jasmineUnderTest.Spec).toHaveBeenCalledWith(jasmine.objectContaining({
throwOnExpectationFailure: true
}));
});
@@ -48,21 +39,120 @@ describe("Env", function() {
it('can configure suites to throw errors on expectation failures', function() {
env.throwOnExpectationFailure(true);
spyOn(j$, 'Suite');
spyOn(jasmineUnderTest, 'Suite');
env.describe('foo', function() {});
expect(j$.Suite).toHaveBeenCalledWith(jasmine.objectContaining({
expect(jasmineUnderTest.Suite).toHaveBeenCalledWith(jasmine.objectContaining({
throwOnExpectationFailure: true
}));
});
describe('#describe', function () {
it("throws an error when given arguments", function() {
expect(function() {
env.describe('done method', function(done) {});
}).toThrowError('describe does not expect any arguments');
});
it('throws an error when it receives a non-fn argument', function() {
// Some versions of PhantomJS return [object DOMWindow] when
// Object.prototype.toString.apply is called with `undefined` or `null`.
// In a similar fashion, IE8 gives [object Object] for both `undefined`
// and `null`. We mostly just want these tests to check that using
// anything other than a function throws an error.
expect(function() {
env.describe('undefined arg', undefined);
}).toThrowError(/describe expects a function argument; received \[object (Undefined|DOMWindow|Object)\]/);
expect(function() {
env.describe('null arg', null);
}).toThrowError(/describe expects a function argument; received \[object (Null|DOMWindow|Object)\]/);
expect(function() {
env.describe('array arg', []);
}).toThrowError('describe expects a function argument; received [object Array]');
expect(function() {
env.describe('object arg', {});
}).toThrowError('describe expects a function argument; received [object Object]');
expect(function() {
env.describe('fn arg', function() {});
}).not.toThrowError('describe expects a function argument; received [object Function]');
});
});
describe('#it', function () {
it('throws an error when it receives a non-fn argument', function() {
expect(function() {
env.it('undefined arg', null);
}).toThrowError(/it expects a function argument; received \[object (Null|DOMWindow|Object)\]/);
});
it('does not throw when it is not given a fn argument', function() {
expect(function() {
env.it('pending spec');
}).not.toThrow();
});
});
describe('#xit', function() {
it('calls spec.pend with "Temporarily disabled with xit"', function() {
var pendSpy = jasmine.createSpy();
spyOn(env, 'it').and.returnValue({
pend: pendSpy
});
env.xit();
env.xit('foo', function() {});
expect(pendSpy).toHaveBeenCalledWith('Temporarily disabled with xit');
});
it('throws an error when it receives a non-fn argument', function() {
expect(function() {
env.xit('undefined arg', null);
}).toThrowError(/xit expects a function argument; received \[object (Null|DOMWindow|Object)\]/);
});
it('does not throw when it is not given a fn argument', function() {
expect(function() {
env.xit('pending spec');
}).not.toThrow();
});
});
describe('#fit', function () {
it('throws an error when it receives a non-fn argument', function() {
expect(function() {
env.fit('undefined arg', undefined);
}).toThrowError(/fit expects a function argument; received \[object (Undefined|DOMWindow|Object)\]/);
});
});
describe('#beforeEach', function () {
it('throws an error when it receives a non-fn argument', function() {
expect(function() {
env.beforeEach(undefined);
}).toThrowError(/beforeEach expects a function argument; received \[object (Undefined|DOMWindow|Object)\]/);
});
});
describe('#beforeAll', function () {
it('throws an error when it receives a non-fn argument', function() {
expect(function() {
env.beforeAll(undefined);
}).toThrowError(/beforeAll expects a function argument; received \[object (Undefined|DOMWindow|Object)\]/);
});
});
describe('#afterEach', function () {
it('throws an error when it receives a non-fn argument', function() {
expect(function() {
env.afterEach(undefined);
}).toThrowError(/afterEach expects a function argument; received \[object (Undefined|DOMWindow|Object)\]/);
});
});
describe('#afterAll', function () {
it('throws an error when it receives a non-fn argument', function() {
expect(function() {
env.afterAll(undefined);
}).toThrowError(/afterAll expects a function argument; received \[object (Undefined|DOMWindow|Object)\]/);
});
});
});

View File

@@ -7,7 +7,7 @@ describe("ExceptionFormatter", function() {
message: 'you got your foo in my bar',
name: 'A Classic Mistake'
},
exceptionFormatter = new j$.ExceptionFormatter(),
exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
message = exceptionFormatter.message(sampleFirefoxException);
expect(message).toEqual('A Classic Mistake: you got your foo in my bar in foo.js (line 1978)');
@@ -20,7 +20,7 @@ describe("ExceptionFormatter", function() {
message: 'you got your foo in my bar',
name: 'A Classic Mistake'
},
exceptionFormatter = new j$.ExceptionFormatter(),
exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
message = exceptionFormatter.message(sampleWebkitException);
expect(message).toEqual('A Classic Mistake: you got your foo in my bar in foo.js (line 1978)');
@@ -31,7 +31,7 @@ describe("ExceptionFormatter", function() {
message: 'you got your foo in my bar',
name: 'A Classic Mistake'
},
exceptionFormatter = new j$.ExceptionFormatter(),
exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
message = exceptionFormatter.message(sampleV8);
expect(message).toEqual('A Classic Mistake: you got your foo in my bar');
@@ -39,7 +39,7 @@ describe("ExceptionFormatter", function() {
it("formats thrown exceptions that aren't errors", function() {
var thrown = "crazy error",
exceptionFormatter = new j$.ExceptionFormatter(),
exceptionFormatter = new jasmineUnderTest.ExceptionFormatter(),
message = exceptionFormatter.message(thrown);
expect(message).toEqual("crazy error thrown");
@@ -53,11 +53,11 @@ describe("ExceptionFormatter", function() {
var error;
try { throw new Error("an error") } catch(e) { error = e; }
expect(new j$.ExceptionFormatter().stack(error)).toMatch(/ExceptionFormatterSpec\.js.*\d+/)
expect(new jasmineUnderTest.ExceptionFormatter().stack(error)).toMatch(/ExceptionFormatterSpec\.js.*\d+/)
});
it("returns null if no Error provided", function() {
expect(new j$.ExceptionFormatter().stack()).toBeNull();
expect(new jasmineUnderTest.ExceptionFormatter().stack()).toBeNull();
});
});
});

View File

@@ -2,7 +2,7 @@ describe('Exceptions:', function() {
var env;
beforeEach(function() {
env = new j$.Env();
env = new jasmineUnderTest.Env();
});
describe('with break on exception', function() {

View File

@@ -1,16 +1,16 @@
describe("buildExpectationResult", function() {
it("defaults to passed", function() {
var result = j$.buildExpectationResult({passed: 'some-value'});
var result = jasmineUnderTest.buildExpectationResult({passed: 'some-value'});
expect(result.passed).toBe('some-value');
});
it("message defaults to Passed for passing specs", function() {
var result = j$.buildExpectationResult({passed: true, message: 'some-value'});
var result = jasmineUnderTest.buildExpectationResult({passed: true, message: 'some-value'});
expect(result.message).toBe('Passed.');
});
it("message returns the message for failing expectations", function() {
var result = j$.buildExpectationResult({passed: false, message: 'some-value'});
var result = jasmineUnderTest.buildExpectationResult({passed: false, message: 'some-value'});
expect(result.message).toBe('some-value');
});
@@ -18,7 +18,7 @@ describe("buildExpectationResult", function() {
var fakeError = {message: 'foo'},
messageFormatter = jasmine.createSpy("exception message formatter").and.returnValue(fakeError.message);
var result = j$.buildExpectationResult(
var result = jasmineUnderTest.buildExpectationResult(
{
passed: false,
error: fakeError,
@@ -33,7 +33,7 @@ describe("buildExpectationResult", function() {
var fakeError = {stack: 'foo'},
stackFormatter = jasmine.createSpy("stack formatter").and.returnValue(fakeError.stack);
var result = j$.buildExpectationResult(
var result = jasmineUnderTest.buildExpectationResult(
{
passed: false,
error: fakeError,
@@ -45,17 +45,17 @@ describe("buildExpectationResult", function() {
});
it("matcherName returns passed matcherName", function() {
var result = j$.buildExpectationResult({matcherName: 'some-value'});
var result = jasmineUnderTest.buildExpectationResult({matcherName: 'some-value'});
expect(result.matcherName).toBe('some-value');
});
it("expected returns passed expected", function() {
var result = j$.buildExpectationResult({expected: 'some-value'});
var result = jasmineUnderTest.buildExpectationResult({expected: 'some-value'});
expect(result.expected).toBe('some-value');
});
it("actual returns passed actual", function() {
var result = j$.buildExpectationResult({actual: 'some-value'});
var result = jasmineUnderTest.buildExpectationResult({actual: 'some-value'});
expect(result.actual).toBe('some-value');
});
});

View File

@@ -6,7 +6,7 @@ describe("Expectation", function() {
},
expectation;
expectation = new j$.Expectation({
expectation = new jasmineUnderTest.Expectation({
customMatchers: matchers
});
@@ -20,18 +20,18 @@ describe("Expectation", function() {
},
expectation;
j$.Expectation.addCoreMatchers(coreMatchers);
jasmineUnderTest.Expectation.addCoreMatchers(coreMatchers);
expectation = new j$.Expectation({});
expectation = new jasmineUnderTest.Expectation({});
expect(expectation.toQuux).toBeDefined();
});
it("Factory builds an expectation/negative expectation", function() {
var builtExpectation = j$.Expectation.Factory();
var builtExpectation = jasmineUnderTest.Expectation.Factory();
expect(builtExpectation instanceof j$.Expectation).toBe(true);
expect(builtExpectation.not instanceof j$.Expectation).toBe(true);
expect(builtExpectation instanceof jasmineUnderTest.Expectation).toBe(true);
expect(builtExpectation.not instanceof jasmineUnderTest.Expectation).toBe(true);
expect(builtExpectation.not.isNot).toBe(true);
});
@@ -46,7 +46,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = new j$.Expectation({
expectation = new jasmineUnderTest.Expectation({
util: util,
customMatchers: matchers,
customEqualityTesters: customEqualityTesters,
@@ -74,7 +74,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = new j$.Expectation({
expectation = new jasmineUnderTest.Expectation({
util: util,
customMatchers: matchers,
actual: "an actual",
@@ -100,7 +100,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = new j$.Expectation({
expectation = new jasmineUnderTest.Expectation({
customMatchers: matchers,
util: util,
actual: "an actual",
@@ -113,6 +113,7 @@ describe("Expectation", function() {
matcherName: "toFoo",
passed: true,
message: "",
error: undefined,
expected: "hello",
actual: "an actual"
});
@@ -132,7 +133,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = new j$.Expectation({
expectation = new jasmineUnderTest.Expectation({
customMatchers: matchers,
util: util,
actual: "an actual",
@@ -146,7 +147,8 @@ describe("Expectation", function() {
passed: false,
expected: "hello",
actual: "an actual",
message: ""
message: "",
error: undefined
});
});
@@ -166,7 +168,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = new j$.Expectation({
expectation = new jasmineUnderTest.Expectation({
actual: "an actual",
customMatchers: matchers,
addExpectationResult: addExpectationResult
@@ -179,7 +181,8 @@ describe("Expectation", function() {
passed: false,
expected: "hello",
actual: "an actual",
message: "I am a custom message"
message: "I am a custom message",
error: undefined
});
});
@@ -199,7 +202,7 @@ describe("Expectation", function() {
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = new j$.Expectation({
expectation = new jasmineUnderTest.Expectation({
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult
@@ -212,7 +215,8 @@ describe("Expectation", function() {
passed: false,
expected: "hello",
actual: "an actual",
message: "I am a custom message"
message: "I am a custom message",
error: undefined
});
});
@@ -231,7 +235,7 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
expectation = new j$.Expectation({
expectation = new jasmineUnderTest.Expectation({
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult,
@@ -244,6 +248,7 @@ describe("Expectation", function() {
matcherName: "toFoo",
passed: true,
message: "",
error: undefined,
expected: "hello",
actual: actual
});
@@ -264,7 +269,7 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
expectation = new j$.Expectation({
expectation = new jasmineUnderTest.Expectation({
customMatchers: matchers,
actual: "an actual",
util: util,
@@ -279,7 +284,8 @@ describe("Expectation", function() {
passed: false,
expected: "hello",
actual: actual,
message: "default message"
message: "default message",
error: undefined
});
});
@@ -300,7 +306,7 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
expectation = new j$.Expectation({
expectation = new jasmineUnderTest.Expectation({
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult,
@@ -314,7 +320,8 @@ describe("Expectation", function() {
passed: false,
expected: "hello",
actual: actual,
message: "I am a custom message"
message: "I am a custom message",
error: undefined
});
});
@@ -331,7 +338,7 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
expectation = new j$.Expectation({
expectation = new jasmineUnderTest.Expectation({
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult,
@@ -345,7 +352,8 @@ describe("Expectation", function() {
passed: true,
expected: "hello",
actual: actual,
message: ""
message: "",
error: undefined
});
});
@@ -367,7 +375,7 @@ describe("Expectation", function() {
actual = "an actual",
expectation;
expectation = new j$.Expectation({
expectation = new jasmineUnderTest.Expectation({
customMatchers: matchers,
actual: "an actual",
addExpectationResult: addExpectationResult,
@@ -381,7 +389,44 @@ describe("Expectation", function() {
passed: false,
expected: "hello",
actual: actual,
message: "I'm a custom message"
message: "I'm a custom message",
error: undefined
});
});
it("reports a custom error message to the spec", function() {
var customError = new Error("I am a custom error");
var matchers = {
toFoo: function() {
return {
compare: function() {
return {
pass: false,
message: "I am a custom message",
error: customError
};
}
};
}
},
addExpectationResult = jasmine.createSpy("addExpectationResult"),
expectation;
expectation = new jasmineUnderTest.Expectation({
actual: "an actual",
customMatchers: matchers,
addExpectationResult: addExpectationResult
});
expectation.toFoo("hello");
expect(addExpectationResult).toHaveBeenCalledWith(false, {
matcherName: "toFoo",
passed: false,
expected: "hello",
actual: "an actual",
message: "I am a custom message",
error: customError
});
});

View File

@@ -0,0 +1,94 @@
describe("GlobalErrors", function() {
it("calls the added handler on error", function() {
var fakeGlobal = { onerror: null },
handler = jasmine.createSpy('errorHandler'),
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
errors.install();
errors.pushListener(handler);
fakeGlobal.onerror('foo');
expect(handler).toHaveBeenCalledWith('foo');
});
it("only calls the most recent handler", function() {
var fakeGlobal = { onerror: null },
handler1 = jasmine.createSpy('errorHandler1'),
handler2 = jasmine.createSpy('errorHandler2'),
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
errors.install();
errors.pushListener(handler1);
errors.pushListener(handler2);
fakeGlobal.onerror('foo');
expect(handler1).not.toHaveBeenCalled();
expect(handler2).toHaveBeenCalledWith('foo');
});
it("calls previous handlers when one is removed", function() {
var fakeGlobal = { onerror: null },
handler1 = jasmine.createSpy('errorHandler1'),
handler2 = jasmine.createSpy('errorHandler2'),
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
errors.install();
errors.pushListener(handler1);
errors.pushListener(handler2);
errors.popListener();
fakeGlobal.onerror('foo');
expect(handler1).toHaveBeenCalledWith('foo');
expect(handler2).not.toHaveBeenCalled();
});
it("uninstalls itself, putting back a previous callback", function() {
var originalCallback = jasmine.createSpy('error'),
fakeGlobal = { onerror: originalCallback },
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
expect(fakeGlobal.onerror).toBe(originalCallback);
errors.install();
expect(fakeGlobal.onerror).not.toBe(originalCallback);
errors.uninstall();
expect(fakeGlobal.onerror).toBe(originalCallback);
});
it("works in node.js", function() {
var fakeGlobal = {
process: {
on: jasmine.createSpy('process.on'),
removeListener: jasmine.createSpy('process.removeListener'),
listeners: jasmine.createSpy('process.listeners').and.returnValue(['foo']),
removeAllListeners: jasmine.createSpy('process.removeAllListeners')
}
},
handler = jasmine.createSpy('errorHandler'),
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
errors.install();
expect(fakeGlobal.process.on).toHaveBeenCalledWith('uncaughtException', jasmine.any(Function));
expect(fakeGlobal.process.listeners).toHaveBeenCalledWith('uncaughtException');
expect(fakeGlobal.process.removeAllListeners).toHaveBeenCalledWith('uncaughtException');
errors.pushListener(handler);
var addedListener = fakeGlobal.process.on.calls.argsFor(0)[1];
addedListener(new Error('bar'));
expect(handler).toHaveBeenCalledWith(new Error('bar'));
errors.uninstall();
expect(fakeGlobal.process.removeListener).toHaveBeenCalledWith('uncaughtException', addedListener);
expect(fakeGlobal.process.on).toHaveBeenCalledWith('uncaughtException', 'foo');
});
});

View File

@@ -5,7 +5,7 @@ xdescribe('JsApiReporter (integration specs)', function() {
var suite, nestedSuite, nestedSpec;
beforeEach(function() {
env = new j$.Env();
env = new jasmineUnderTest.Env();
suite = env.describe("top-level suite", function() {
spec1 = env.it("spec 1", function() {
@@ -25,7 +25,7 @@ xdescribe('JsApiReporter (integration specs)', function() {
});
reporter = new j$.JsApiReporter({});
reporter = new jasmineUnderTest.JsApiReporter({});
env.addReporter(reporter);
env.execute();
@@ -82,7 +82,7 @@ xdescribe('JsApiReporter (integration specs)', function() {
describe("JsApiReporter", function() {
it("knows when a full environment is started", function() {
var reporter = new j$.JsApiReporter({});
var reporter = new jasmineUnderTest.JsApiReporter({});
expect(reporter.started).toBe(false);
expect(reporter.finished).toBe(false);
@@ -94,7 +94,7 @@ describe("JsApiReporter", function() {
});
it("knows when a full environment is done", function() {
var reporter = new j$.JsApiReporter({});
var reporter = new jasmineUnderTest.JsApiReporter({});
expect(reporter.started).toBe(false);
expect(reporter.finished).toBe(false);
@@ -106,13 +106,13 @@ describe("JsApiReporter", function() {
});
it("defaults to 'loaded' status", function() {
var reporter = new j$.JsApiReporter({});
var reporter = new jasmineUnderTest.JsApiReporter({});
expect(reporter.status()).toEqual('loaded');
});
it("reports 'started' when Jasmine has started", function() {
var reporter = new j$.JsApiReporter({});
var reporter = new jasmineUnderTest.JsApiReporter({});
reporter.jasmineStarted();
@@ -120,7 +120,7 @@ describe("JsApiReporter", function() {
});
it("reports 'done' when Jasmine is done", function() {
var reporter = new j$.JsApiReporter({});
var reporter = new jasmineUnderTest.JsApiReporter({});
reporter.jasmineDone({});
@@ -128,7 +128,7 @@ describe("JsApiReporter", function() {
});
it("tracks a suite", function() {
var reporter = new j$.JsApiReporter({});
var reporter = new jasmineUnderTest.JsApiReporter({});
reporter.suiteStarted({
id: 123,
@@ -151,7 +151,7 @@ describe("JsApiReporter", function() {
describe("#specResults", function() {
var reporter, specResult1, specResult2;
beforeEach(function() {
reporter = new j$.JsApiReporter({});
reporter = new jasmineUnderTest.JsApiReporter({});
specResult1 = {
id: 1,
description: "A spec"
@@ -181,7 +181,7 @@ describe("JsApiReporter", function() {
describe("#suiteResults", function(){
var reporter, suiteResult1, suiteResult2;
beforeEach(function() {
reporter = new j$.JsApiReporter({});
reporter = new jasmineUnderTest.JsApiReporter({});
suiteStarted1 = {
id: 1
};
@@ -218,7 +218,7 @@ describe("JsApiReporter", function() {
describe("#executionTime", function() {
it("should start the timer when jasmine starts", function() {
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
reporter = new j$.JsApiReporter({
reporter = new jasmineUnderTest.JsApiReporter({
timer: timerSpy
});
@@ -228,7 +228,7 @@ describe("JsApiReporter", function() {
it("should return the time it took the specs to run, in ms", function() {
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
reporter = new j$.JsApiReporter({
reporter = new jasmineUnderTest.JsApiReporter({
timer: timerSpy
});
@@ -240,7 +240,7 @@ describe("JsApiReporter", function() {
describe("when the specs haven't finished being run", function() {
it("should return undefined", function() {
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
reporter = new j$.JsApiReporter({
reporter = new jasmineUnderTest.JsApiReporter({
timer: timerSpy
});
@@ -251,7 +251,7 @@ describe("JsApiReporter", function() {
describe('#runDetails', function() {
it('should have details about the run', function() {
var reporter = new j$.JsApiReporter({});
var reporter = new jasmineUnderTest.JsApiReporter({});
reporter.jasmineDone({some: {run: 'details'}});
expect(reporter.runDetails).toEqual({some: {run: 'details'}});
});

View File

@@ -1,7 +1,7 @@
describe("FakeDate", function() {
it("does not fail if no global date is found", function() {
var fakeGlobal = {},
mockDate = new j$.MockDate(fakeGlobal);
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
expect(function() {
mockDate.install();
@@ -17,7 +17,7 @@ describe("FakeDate", function() {
}
}),
fakeGlobal = { Date: globalDate },
mockDate = new j$.MockDate(fakeGlobal);
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
expect(fakeGlobal.Date).toEqual(globalDate);
mockDate.install();
@@ -32,7 +32,7 @@ describe("FakeDate", function() {
}
}),
fakeGlobal = { Date: globalDate },
mockDate = new j$.MockDate(fakeGlobal);
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
mockDate.install();
mockDate.uninstall();
@@ -49,7 +49,7 @@ describe("FakeDate", function() {
}
}),
fakeGlobal = { Date: globalDate },
mockDate = new j$.MockDate(fakeGlobal);
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
mockDate.install();
@@ -60,7 +60,7 @@ describe("FakeDate", function() {
it("can accept a date as time base when installing", function() {
var fakeGlobal = { Date: Date },
mockDate = new j$.MockDate(fakeGlobal),
mockDate = new jasmineUnderTest.MockDate(fakeGlobal),
baseDate = new Date();
spyOn(baseDate, 'getTime').and.returnValue(123);
@@ -71,7 +71,7 @@ describe("FakeDate", function() {
it("makes real dates", function() {
var fakeGlobal = { Date: Date },
mockDate = new j$.MockDate(fakeGlobal);
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
mockDate.install();
expect(new fakeGlobal.Date()).toEqual(jasmine.any(Date));
@@ -89,7 +89,7 @@ describe("FakeDate", function() {
fakeGlobal = { Date: globalDate };
globalDate.now = function() {};
var mockDate = new j$.MockDate(fakeGlobal);
var mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
mockDate.install();
@@ -105,7 +105,7 @@ describe("FakeDate", function() {
}
}),
fakeGlobal = { Date: globalDate },
mockDate = new j$.MockDate(fakeGlobal);
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
mockDate.install();
@@ -123,7 +123,7 @@ describe("FakeDate", function() {
fakeGlobal = { Date: globalDate };
globalDate.now = function() {};
var mockDate = new j$.MockDate(fakeGlobal);
var mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
mockDate.install();
@@ -147,7 +147,7 @@ describe("FakeDate", function() {
fakeGlobal = { Date: globalDate };
globalDate.now = function() {};
var mockDate = new j$.MockDate(fakeGlobal);
var mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
mockDate.install();
@@ -160,7 +160,7 @@ describe("FakeDate", function() {
it("allows creation of a Date in a different time than the mocked time", function() {
var fakeGlobal = { Date: Date },
mockDate = new j$.MockDate(fakeGlobal);
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
mockDate.install();
@@ -170,7 +170,7 @@ describe("FakeDate", function() {
it("allows creation of a Date that isn't fully specified", function() {
var fakeGlobal = { Date: Date },
mockDate = new j$.MockDate(fakeGlobal);
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
mockDate.install();
@@ -180,7 +180,7 @@ describe("FakeDate", function() {
it('allows creation of a Date with millis', function() {
var fakeGlobal = { Date: Date },
mockDate = new j$.MockDate(fakeGlobal),
mockDate = new jasmineUnderTest.MockDate(fakeGlobal),
now = new Date(2014, 3, 15).getTime();
mockDate.install();
@@ -191,7 +191,7 @@ describe("FakeDate", function() {
it("copies all Date properties to the mocked date", function() {
var fakeGlobal = { Date: Date },
mockDate = new j$.MockDate(fakeGlobal);
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
mockDate.install();

View File

@@ -1,34 +1,53 @@
describe("j$.pp", function () {
describe("jasmineUnderTest.pp", function () {
it("should wrap strings in single quotes", function() {
expect(j$.pp("some string")).toEqual("'some string'");
expect(j$.pp("som' string")).toEqual("'som' string'");
expect(jasmineUnderTest.pp("some string")).toEqual("'some string'");
expect(jasmineUnderTest.pp("som' string")).toEqual("'som' string'");
});
it("should stringify primitives properly", function() {
expect(j$.pp(true)).toEqual("true");
expect(j$.pp(false)).toEqual("false");
expect(j$.pp(null)).toEqual("null");
expect(j$.pp(jasmine.undefined)).toEqual("undefined");
expect(j$.pp(3)).toEqual("3");
expect(j$.pp(-3.14)).toEqual("-3.14");
expect(j$.pp(-0)).toEqual("-0");
expect(jasmineUnderTest.pp(true)).toEqual("true");
expect(jasmineUnderTest.pp(false)).toEqual("false");
expect(jasmineUnderTest.pp(null)).toEqual("null");
expect(jasmineUnderTest.pp(jasmine.undefined)).toEqual("undefined");
expect(jasmineUnderTest.pp(3)).toEqual("3");
expect(jasmineUnderTest.pp(-3.14)).toEqual("-3.14");
expect(jasmineUnderTest.pp(-0)).toEqual("-0");
});
describe('stringify sets', function() {
it("should stringify sets properly", function() {
jasmine.getEnv().requireFunctioningSets();
expect(jasmineUnderTest.pp(new Set([1, 2]))).toEqual("Set( 1, 2 )");
});
it("should truncate sets with more elments than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH", function() {
jasmine.getEnv().requireFunctioningSets();
var originalMaxSize = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
try {
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
expect(jasmineUnderTest.pp(new Set(["a", "b", "c"]))).toEqual("Set( 'a', 'b', ... )");
} finally {
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxSize;
}
})
});
describe('stringify arrays', function() {
it("should stringify arrays properly", function() {
expect(j$.pp([1, 2])).toEqual("[ 1, 2 ]");
expect(j$.pp([1, 'foo', {}, jasmine.undefined, null])).toEqual("[ 1, 'foo', Object({ }), undefined, null ]");
expect(jasmineUnderTest.pp([1, 2])).toEqual("[ 1, 2 ]");
expect(jasmineUnderTest.pp([1, 'foo', {}, jasmine.undefined, null])).toEqual("[ 1, 'foo', Object({ }), undefined, null ]");
});
it("should truncate arrays that are longer than j$.MAX_PRETTY_PRINT_ARRAY_LENGTH", function() {
var originalMaxLength = j$.MAX_PRETTY_PRINT_ARRAY_LENGTH;
it("should truncate arrays that are longer than jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH", function() {
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
var array = [1, 2, 3];
try {
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
expect(j$.pp(array)).toEqual("[ 1, 2, ... ]");
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
expect(jasmineUnderTest.pp(array)).toEqual("[ 1, 2, ... ]");
} finally {
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
}
});
@@ -36,27 +55,27 @@ describe("j$.pp", function () {
var arr = [1, 2];
arr.foo = 'bar';
arr.baz = {};
expect(j$.pp(arr)).toEqual("[ 1, 2, foo: 'bar', baz: Object({ }) ]");
expect(jasmineUnderTest.pp(arr)).toEqual("[ 1, 2, foo: 'bar', baz: Object({ }) ]");
});
it("should stringify empty arrays with properties properly", function() {
var empty = [];
empty.foo = 'bar';
empty.baz = {};
expect(j$.pp(empty)).toEqual("[ foo: 'bar', baz: Object({ }) ]");
expect(jasmineUnderTest.pp(empty)).toEqual("[ foo: 'bar', baz: Object({ }) ]");
});
it("should stringify long arrays with properties properly", function() {
var originalMaxLength = j$.MAX_PRETTY_PRINT_ARRAY_LENGTH;
var originalMaxLength = jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH;
var long = [1,2,3];
long.foo = 'bar';
long.baz = {};
try {
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
expect(j$.pp(long)).toEqual("[ 1, 2, ..., foo: 'bar', baz: Object({ }) ]");
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
expect(jasmineUnderTest.pp(long)).toEqual("[ 1, 2, ..., foo: 'bar', baz: Object({ }) ]");
} finally {
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
jasmineUnderTest.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
}
});
@@ -64,49 +83,54 @@ describe("j$.pp", function () {
var array1 = [1, 2];
var array2 = [array1];
array1.push(array2);
expect(j$.pp(array1)).toEqual("[ 1, 2, [ <circular reference: Array> ] ]");
expect(jasmineUnderTest.pp(array1)).toEqual("[ 1, 2, [ <circular reference: Array> ] ]");
});
it("should not indicate circular references incorrectly", function() {
var array = [ [1] ];
expect(j$.pp(array)).toEqual("[ [ 1 ] ]");
expect(jasmineUnderTest.pp(array)).toEqual("[ [ 1 ] ]");
});
});
it("should stringify objects properly", function() {
expect(j$.pp({foo: 'bar'})).toEqual("Object({ foo: 'bar' })");
expect(j$.pp({foo:'bar', baz:3, nullValue: null, undefinedValue: jasmine.undefined})).toEqual("Object({ foo: 'bar', baz: 3, nullValue: null, undefinedValue: undefined })");
expect(j$.pp({foo: function () {
expect(jasmineUnderTest.pp({foo: 'bar'})).toEqual("Object({ foo: 'bar' })");
expect(jasmineUnderTest.pp({foo:'bar', baz:3, nullValue: null, undefinedValue: jasmine.undefined})).toEqual("Object({ foo: 'bar', baz: 3, nullValue: null, undefinedValue: undefined })");
expect(jasmineUnderTest.pp({foo: function () {
}, bar: [1, 2, 3]})).toEqual("Object({ foo: Function, bar: [ 1, 2, 3 ] })");
});
it("should print 'null' as the constructor of an object with its own constructor property", function() {
expect(jasmineUnderTest.pp({constructor: function() {}})).toContain("null({");
expect(jasmineUnderTest.pp({constructor: 'foo'})).toContain("null({");
});
it("should not include inherited properties when stringifying an object", function() {
var SomeClass = function SomeClass() {};
SomeClass.prototype.foo = "inherited foo";
var instance = new SomeClass();
instance.bar = "my own bar";
expect(j$.pp(instance)).toEqual("SomeClass({ bar: 'my own bar' })");
expect(jasmineUnderTest.pp(instance)).toEqual("SomeClass({ bar: 'my own bar' })");
});
it("should not recurse objects and arrays more deeply than j$.MAX_PRETTY_PRINT_DEPTH", function() {
var originalMaxDepth = j$.MAX_PRETTY_PRINT_DEPTH;
it("should not recurse objects and arrays more deeply than jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH", function() {
var originalMaxDepth = jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH;
var nestedObject = { level1: { level2: { level3: { level4: "leaf" } } } };
var nestedArray = [1, [2, [3, [4, "leaf"]]]];
try {
j$.MAX_PRETTY_PRINT_DEPTH = 2;
expect(j$.pp(nestedObject)).toEqual("Object({ level1: Object({ level2: Object }) })");
expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, Array ] ]");
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 2;
expect(jasmineUnderTest.pp(nestedObject)).toEqual("Object({ level1: Object({ level2: Object }) })");
expect(jasmineUnderTest.pp(nestedArray)).toEqual("[ 1, [ 2, Array ] ]");
j$.MAX_PRETTY_PRINT_DEPTH = 3;
expect(j$.pp(nestedObject)).toEqual("Object({ level1: Object({ level2: Object({ level3: Object }) }) })");
expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, Array ] ] ]");
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 3;
expect(jasmineUnderTest.pp(nestedObject)).toEqual("Object({ level1: Object({ level2: Object({ level3: Object }) }) })");
expect(jasmineUnderTest.pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, Array ] ] ]");
j$.MAX_PRETTY_PRINT_DEPTH = 4;
expect(j$.pp(nestedObject)).toEqual("Object({ level1: Object({ level2: Object({ level3: Object({ level4: 'leaf' }) }) }) })");
expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, [ 4, 'leaf' ] ] ] ]");
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = 4;
expect(jasmineUnderTest.pp(nestedObject)).toEqual("Object({ level1: Object({ level2: Object({ level3: Object({ level4: 'leaf' }) }) }) })");
expect(jasmineUnderTest.pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, [ 4, 'leaf' ] ] ] ]");
} finally {
j$.MAX_PRETTY_PRINT_DEPTH = originalMaxDepth;
jasmineUnderTest.MAX_PRETTY_PRINT_DEPTH = originalMaxDepth;
}
});
@@ -115,18 +139,18 @@ describe("j$.pp", function () {
var frozenObject = {foo: {bar: 'baz'}};
frozenObject.circular = frozenObject;
frozenObject = Object.freeze(frozenObject);
expect(j$.pp(frozenObject)).toEqual("Object({ foo: Object({ bar: 'baz' }), circular: <circular reference: Object> })");
expect(jasmineUnderTest.pp(frozenObject)).toEqual("Object({ foo: Object({ bar: 'baz' }), circular: <circular reference: Object> })");
}
});
it("should stringify RegExp objects properly", function() {
expect(j$.pp(/x|y|z/)).toEqual("/x|y|z/");
expect(jasmineUnderTest.pp(/x|y|z/)).toEqual("/x|y|z/");
});
it("should indicate circular object references", function() {
var sampleValue = {foo: 'hello'};
sampleValue.nested = sampleValue;
expect(j$.pp(sampleValue)).toEqual("Object({ foo: 'hello', nested: <circular reference: Object> })");
expect(jasmineUnderTest.pp(sampleValue)).toEqual("Object({ foo: 'hello', nested: <circular reference: Object> })");
});
it("should indicate getters on objects as such", function() {
@@ -138,39 +162,38 @@ describe("j$.pp", function () {
});
}
if (sampleValue.__defineGetter__) {
expect(j$.pp(sampleValue)).toEqual("Object({ id: 1, calculatedValue: <getter> })");
expect(jasmineUnderTest.pp(sampleValue)).toEqual("Object({ id: 1, calculatedValue: <getter> })");
}
else {
expect(j$.pp(sampleValue)).toEqual("Object({ id: 1 })");
expect(jasmineUnderTest.pp(sampleValue)).toEqual("Object({ id: 1 })");
}
});
it('should not do HTML escaping of strings', function() {
expect(j$.pp('some <b>html string</b> &', false)).toEqual('\'some <b>html string</b> &\'');
expect(jasmineUnderTest.pp('some <b>html string</b> &', false)).toEqual('\'some <b>html string</b> &\'');
});
it("should abbreviate the global (usually window) object", function() {
expect(j$.pp(jasmine.getGlobal())).toEqual("<global>");
expect(jasmineUnderTest.pp(jasmine.getGlobal())).toEqual("<global>");
});
it("should stringify Date objects properly", function() {
var now = new Date();
expect(j$.pp(now)).toEqual("Date(" + now.toString() + ")");
expect(jasmineUnderTest.pp(now)).toEqual("Date(" + now.toString() + ")");
});
it("should stringify spy objects properly", function() {
var TestObject = {
someFunction: function() {}
},
env = new j$.Env();
env = new jasmineUnderTest.Env();
var spyRegistry = new j$.SpyRegistry({currentSpies: function() {return [];}});
var spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() {return [];}});
spyRegistry.spyOn(TestObject, 'someFunction');
expect(j$.pp(TestObject.someFunction)).toEqual("spy on someFunction");
expect(jasmineUnderTest.pp(TestObject.someFunction)).toEqual("spy on someFunction");
expect(j$.pp(j$.createSpy("something"))).toEqual("spy on something");
expect(jasmineUnderTest.pp(jasmineUnderTest.createSpy("something"))).toEqual("spy on something");
});
it("should stringify objects that implement jasmineToString", function () {
@@ -178,7 +201,7 @@ describe("j$.pp", function () {
jasmineToString: function () { return "strung"; }
};
expect(j$.pp(obj)).toEqual("strung");
expect(jasmineUnderTest.pp(obj)).toEqual("strung");
});
it("should stringify objects that implement custom toString", function () {
@@ -186,7 +209,29 @@ describe("j$.pp", function () {
toString: function () { return "my toString"; }
};
expect(j$.pp(obj)).toEqual("my toString");
expect(jasmineUnderTest.pp(obj)).toEqual("my toString");
// Simulate object from another global context (e.g. an iframe or Web Worker) that does not actually have a custom
// toString despite obj.toString !== Object.prototype.toString
var objFromOtherContext = {
foo: 'bar',
toString: function () { return Object.prototype.toString.call(this); }
};
if (jasmine.getEnv().ieVersion < 9) {
expect(jasmineUnderTest.pp(objFromOtherContext)).toEqual("Object({ foo: 'bar' })");
} else {
expect(jasmineUnderTest.pp(objFromOtherContext)).toEqual("Object({ foo: 'bar', toString: Function })");
}
});
it("should stringify objects from anonymous constructors with custom toString", function () {
var MyAnonymousConstructor = (function() { return function () {}; })();
MyAnonymousConstructor.toString = function () { return ''; };
var a = new MyAnonymousConstructor();
expect(jasmineUnderTest.pp(a)).toEqual("<anonymous>({ })");
});
it("should handle objects with null prototype", function() {
@@ -195,6 +240,6 @@ describe("j$.pp", function () {
var obj = Object.create(null);
obj.foo = 'bar';
expect(j$.pp(obj)).toEqual("null({ foo: 'bar' })");
expect(jasmineUnderTest.pp(obj)).toEqual("null({ foo: 'bar' })");
});
});

View File

@@ -4,7 +4,7 @@ describe("QueueRunner", function() {
var calls = [],
queueableFn1 = { fn: jasmine.createSpy('fn1') },
queueableFn2 = { fn: jasmine.createSpy('fn2') },
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn1, queueableFn2]
});
queueableFn1.fn.and.callFake(function() {
@@ -23,7 +23,7 @@ describe("QueueRunner", function() {
var queueableFn1 = { fn: jasmine.createSpy('fn1') },
queueableFn2 = { fn: jasmine.createSpy('fn2') },
queueableFn3 = { fn: function(done) { asyncContext = this; done(); } },
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn1, queueableFn2, queueableFn3]
}),
asyncContext;
@@ -65,7 +65,7 @@ describe("QueueRunner", function() {
afterCallback();
setTimeout(done, 100);
} },
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn1, queueableFn2, queueableFn3],
onComplete: onComplete
});
@@ -99,7 +99,7 @@ describe("QueueRunner", function() {
} },
queueableFn2 = { fn: jasmine.createSpy('fn2') },
failFn = jasmine.createSpy('fail'),
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn1, queueableFn2],
fail: failFn
});
@@ -121,7 +121,7 @@ describe("QueueRunner", function() {
queueableFn = { fn: jasmine.createSpy('fn'), type: 'queueable' },
onComplete = jasmine.createSpy('onComplete'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [beforeFn, queueableFn],
onComplete: onComplete,
onException: onException
@@ -142,7 +142,7 @@ describe("QueueRunner", function() {
queueableFn = { fn: jasmine.createSpy('fn') },
onComplete = jasmine.createSpy('onComplete'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [beforeFn, queueableFn],
onComplete: onComplete,
onException: onException,
@@ -151,7 +151,7 @@ describe("QueueRunner", function() {
queueRunner.execute();
expect(queueableFn.fn).not.toHaveBeenCalled();
jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL);
jasmine.clock().tick(jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL);
expect(onException).not.toHaveBeenCalled();
expect(queueableFn.fn).not.toHaveBeenCalled();
@@ -162,7 +162,7 @@ describe("QueueRunner", function() {
var queueableFn = { fn: function(done) { throw new Error("error!"); } },
onComplete = jasmine.createSpy('onComplete'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn],
onComplete: onComplete,
onException: onException
@@ -173,7 +173,7 @@ describe("QueueRunner", function() {
expect(onComplete).toHaveBeenCalled();
expect(onException).toHaveBeenCalled();
jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL);
jasmine.clock().tick(jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL);
expect(onException.calls.count()).toEqual(1);
});
@@ -181,7 +181,7 @@ describe("QueueRunner", function() {
var queueableFn = { fn: function(done) { done(); } },
onComplete = jasmine.createSpy('onComplete'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn],
onComplete: onComplete,
onException: onException
@@ -191,14 +191,14 @@ describe("QueueRunner", function() {
expect(onComplete).toHaveBeenCalled();
jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL);
jasmine.clock().tick(jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL);
expect(onException).not.toHaveBeenCalled();
});
it("only moves to the next spec the first time you call done", function() {
var queueableFn = { fn: function(done) {done(); done();} },
nextQueueableFn = { fn: jasmine.createSpy('nextFn') };
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn, nextQueueableFn]
});
@@ -212,7 +212,7 @@ describe("QueueRunner", function() {
throw new Error('error!');
} },
nextQueueableFn = { fn: jasmine.createSpy('nextFn') };
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn, nextQueueableFn]
});
@@ -220,6 +220,57 @@ describe("QueueRunner", function() {
jasmine.clock().tick(1);
expect(nextQueueableFn.fn.calls.count()).toEqual(1);
});
it("should return a null when you call done", function () {
// Some promises want handlers to return anything but undefined to help catch "forgotten returns".
var doneReturn,
queueableFn = { fn: function(done) {
doneReturn = done();
} },
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn]
});
queueRunner.execute();
expect(doneReturn).toBe(null);
});
it("continues running functions when an exception is thrown in async code without timing out", function() {
var queueableFn = { fn: function(done) { throwAsync(); }, timeout: function() { return 1; } },
nextQueueableFn = { fn: jasmine.createSpy("nextFunction") },
onException = jasmine.createSpy('onException'),
globalErrors = { pushListener: jasmine.createSpy('pushListener'), popListener: jasmine.createSpy('popListener') },
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn, nextQueueableFn],
onException: onException,
globalErrors: globalErrors
}),
throwAsync = function() {
globalErrors.pushListener.calls.mostRecent().args[0](new Error('foo'));
jasmine.clock().tick(2);
};
nextQueueableFn.fn.and.callFake(function() {
// should remove the same function that was added
expect(globalErrors.popListener).toHaveBeenCalledWith(globalErrors.pushListener.calls.argsFor(0)[0]);
});
queueRunner.execute();
function errorWithMessage(message) {
return {
asymmetricMatch: function(other) {
return new RegExp(message).test(other.message);
},
toString: function() {
return '<Error with message like "' + message + '">';
}
};
}
expect(onException).not.toHaveBeenCalledWith(errorWithMessage(/DEFAULT_TIMEOUT_INTERVAL/));
expect(onException).toHaveBeenCalledWith(errorWithMessage(/^foo$/));
expect(nextQueueableFn.fn).toHaveBeenCalled();
});
});
it("calls exception handlers when an exception is thrown in a fn", function() {
@@ -228,7 +279,7 @@ describe("QueueRunner", function() {
throw new Error('fake error');
} },
onExceptionCallback = jasmine.createSpy('on exception callback'),
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn],
onException: onExceptionCallback
});
@@ -242,7 +293,7 @@ describe("QueueRunner", function() {
var queueableFn = { fn: function() {
throw new Error('fake error');
} },
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn],
catchException: function(e) { return false; }
});
@@ -255,7 +306,7 @@ describe("QueueRunner", function() {
it("continues running the functions even after an exception is thrown in an async spec", function() {
var queueableFn = { fn: function(done) { throw new Error("error"); } },
nextQueueableFn = { fn: jasmine.createSpy("nextFunction") },
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn, nextQueueableFn]
});
@@ -266,7 +317,7 @@ describe("QueueRunner", function() {
it("calls a provided complete callback when done", function() {
var queueableFn = { fn: jasmine.createSpy('fn') },
completeCallback = jasmine.createSpy('completeCallback'),
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn],
onComplete: completeCallback
});
@@ -281,7 +332,7 @@ describe("QueueRunner", function() {
afterFn = { fn: jasmine.createSpy('afterFn') },
completeCallback = jasmine.createSpy('completeCallback'),
clearStack = jasmine.createSpy('clearStack'),
queueRunner = new j$.QueueRunner({
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [asyncFn, afterFn],
clearStack: clearStack,
onComplete: completeCallback

View File

@@ -1,7 +1,7 @@
describe("ReportDispatcher", function() {
it("builds an interface of requested methods", function() {
var dispatcher = new j$.ReportDispatcher(['foo', 'bar', 'baz']);
var dispatcher = new jasmineUnderTest.ReportDispatcher(['foo', 'bar', 'baz']);
expect(dispatcher.foo).toBeDefined();
expect(dispatcher.bar).toBeDefined();
@@ -9,7 +9,7 @@ describe("ReportDispatcher", function() {
});
it("dispatches requested methods to added reporters", function() {
var dispatcher = new j$.ReportDispatcher(['foo', 'bar']),
var dispatcher = new jasmineUnderTest.ReportDispatcher(['foo', 'bar']),
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
anotherReporter = jasmine.createSpyObj('reporter', ['foo', 'bar']);
@@ -28,7 +28,7 @@ describe("ReportDispatcher", function() {
});
it("does not dispatch to a reporter if the reporter doesn't accept the method", function() {
var dispatcher = new j$.ReportDispatcher(['foo']),
var dispatcher = new jasmineUnderTest.ReportDispatcher(['foo']),
reporter = jasmine.createSpyObj('reporter', ['baz']);
dispatcher.addReporter(reporter);
@@ -37,4 +37,43 @@ describe("ReportDispatcher", function() {
dispatcher.foo(123, 456);
}).not.toThrow();
});
it("allows providing a fallback reporter in case there's no other report", function() {
var dispatcher = new jasmineUnderTest.ReportDispatcher(['foo', 'bar']),
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']);
dispatcher.provideFallbackReporter(reporter);
dispatcher.foo(123, 456);
expect(reporter.foo).toHaveBeenCalledWith(123, 456);
});
it("does not call fallback reporting methods when another report is provided", function() {
var dispatcher = new jasmineUnderTest.ReportDispatcher(['foo', 'bar']),
reporter = jasmine.createSpyObj('reporter', ['foo', 'bar']),
fallbackReporter = jasmine.createSpyObj('otherReporter', ['foo', 'bar']);
dispatcher.provideFallbackReporter(fallbackReporter);
dispatcher.addReporter(reporter);
dispatcher.foo(123, 456);
expect(reporter.foo).toHaveBeenCalledWith(123, 456);
expect(fallbackReporter.foo).not.toHaveBeenCalledWith(123, 456);
});
it("allows registered reporters to be cleared", function() {
var dispatcher = new jasmineUnderTest.ReportDispatcher(['foo', 'bar']),
reporter1 = jasmine.createSpyObj('reporter1', ['foo', 'bar']),
reporter2 = jasmine.createSpyObj('reporter2', ['foo', 'bar']);
dispatcher.addReporter(reporter1);
dispatcher.foo(123);
expect(reporter1.foo).toHaveBeenCalledWith(123);
dispatcher.clearReporters();
dispatcher.addReporter(reporter2);
dispatcher.bar(456);
expect(reporter1.bar).not.toHaveBeenCalled();
expect(reporter2.bar).toHaveBeenCalledWith(456);
});
});

View File

@@ -1,36 +1,36 @@
describe("Spec", function() {
it("#isPendingSpecException returns true for a pending spec exception", function() {
var e = new Error(j$.Spec.pendingSpecExceptionMessage);
var e = new Error(jasmineUnderTest.Spec.pendingSpecExceptionMessage);
expect(j$.Spec.isPendingSpecException(e)).toBe(true);
expect(jasmineUnderTest.Spec.isPendingSpecException(e)).toBe(true);
});
it("#isPendingSpecException returns true for a pending spec exception (even when FF bug is present)", function() {
var fakeError = {
toString: function() { return "Error: " + j$.Spec.pendingSpecExceptionMessage; }
toString: function() { return "Error: " + jasmineUnderTest.Spec.pendingSpecExceptionMessage; }
};
expect(j$.Spec.isPendingSpecException(fakeError)).toBe(true);
expect(jasmineUnderTest.Spec.isPendingSpecException(fakeError)).toBe(true);
});
it("#isPendingSpecException returns true for a pending spec exception with a custom message", function() {
expect(j$.Spec.isPendingSpecException(j$.Spec.pendingSpecExceptionMessage + 'foo')).toBe(true);
expect(jasmineUnderTest.Spec.isPendingSpecException(jasmineUnderTest.Spec.pendingSpecExceptionMessage + 'foo')).toBe(true);
});
it("#isPendingSpecException returns false for not a pending spec exception", function() {
var e = new Error("foo");
expect(j$.Spec.isPendingSpecException(e)).toBe(false);
expect(jasmineUnderTest.Spec.isPendingSpecException(e)).toBe(false);
});
it("#isPendingSpecException returns false for thrown values that don't have toString", function() {
expect(j$.Spec.isPendingSpecException(void 0)).toBe(false);
expect(jasmineUnderTest.Spec.isPendingSpecException(void 0)).toBe(false);
});
it("delegates execution to a QueueRunner", function() {
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
description: 'my test',
id: 'some-id',
queueableFn: { fn: function() {} },
@@ -45,7 +45,7 @@ describe("Spec", function() {
it("should call the start callback on execution", function() {
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
startCallback = jasmine.createSpy('startCallback'),
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
id: 123,
description: 'foo bar',
queueableFn: { fn: function() {} },
@@ -69,7 +69,7 @@ describe("Spec", function() {
startCallback = jasmine.createSpy('start-callback').and.callFake(function() {
expect(beforesWereCalled).toBe(false);
}),
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
queueableFn: { fn: function() {} },
beforeFns: function() {
return [function() {
@@ -93,7 +93,7 @@ describe("Spec", function() {
expect(before).toHaveBeenCalled();
expect(after).not.toHaveBeenCalled();
}) },
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
queueableFn: queueableFn,
beforeAndAfterFns: function() {
return {befores: [before], afters: [after]}
@@ -112,7 +112,7 @@ describe("Spec", function() {
startCallback = jasmine.createSpy('startCallback'),
resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
onStart: startCallback,
queueableFn: { fn: null },
resultCallback: resultCallback,
@@ -127,7 +127,7 @@ describe("Spec", function() {
startCallback = jasmine.createSpy('startCallback'),
specBody = jasmine.createSpy('specBody'),
resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
onStart:startCallback,
queueableFn: { fn: specBody },
resultCallback: resultCallback,
@@ -152,7 +152,7 @@ describe("Spec", function() {
startCallback = jasmine.createSpy('startCallback'),
specBody = jasmine.createSpy('specBody'),
resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
onStart:startCallback,
queueableFn: { fn: specBody },
resultCallback: resultCallback,
@@ -174,7 +174,7 @@ describe("Spec", function() {
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
startCallback = jasmine.createSpy('startCallback'),
resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
onStart: startCallback,
resultCallback: resultCallback,
description: "with a spec",
@@ -207,7 +207,7 @@ describe("Spec", function() {
it("should call the done callback on execution complete", function() {
var done = jasmine.createSpy('done callback'),
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
queueableFn: { fn: function() {} },
catchExceptions: function() { return false; },
resultCallback: function() {},
@@ -220,18 +220,18 @@ describe("Spec", function() {
});
it("#status returns passing by default", function() {
var spec = new j$.Spec({queueableFn: { fn: jasmine.createSpy("spec body")} });
var spec = new jasmineUnderTest.Spec({queueableFn: { fn: jasmine.createSpy("spec body")} });
expect(spec.status()).toBe('passed');
});
it("#status returns passed if all expectations in the spec have passed", function() {
var spec = new j$.Spec({queueableFn: { fn: jasmine.createSpy("spec body")} });
var spec = new jasmineUnderTest.Spec({queueableFn: { fn: jasmine.createSpy("spec body")} });
spec.addExpectationResult(true);
expect(spec.status()).toBe('passed');
});
it("#status returns failed if any expectations in the spec have failed", function() {
var spec = new j$.Spec({queueableFn: { fn: jasmine.createSpy("spec body") } });
var spec = new jasmineUnderTest.Spec({queueableFn: { fn: jasmine.createSpy("spec body") } });
spec.addExpectationResult(true);
spec.addExpectationResult(false);
expect(spec.status()).toBe('failed');
@@ -239,7 +239,7 @@ describe("Spec", function() {
it("keeps track of passed and failed expectations", function() {
var resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
queueableFn: { fn: jasmine.createSpy("spec body") },
expectationResultFactory: function (data) { return data; },
queueRunnerFactory: function(attrs) { attrs.onComplete(); },
@@ -256,7 +256,7 @@ describe("Spec", function() {
it("throws an ExpectationFailed error upon receiving a failed expectation when 'throwOnExpectationFailure' is set", function() {
var resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
queueableFn: { fn: function() {} },
expectationResultFactory: function(data) { return data; },
queueRunnerFactory: function(attrs) { attrs.onComplete(); },
@@ -267,7 +267,7 @@ describe("Spec", function() {
spec.addExpectationResult(true, 'passed');
expect(function() {
spec.addExpectationResult(false, 'failed')
}).toThrowError(j$.errors.ExpectationFailed);
}).toThrowError(jasmineUnderTest.errors.ExpectationFailed);
spec.execute();
@@ -277,7 +277,7 @@ describe("Spec", function() {
it("does not throw an ExpectationFailed error when handling an error", function() {
var resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
queueableFn: { fn: function() {} },
expectationResultFactory: function(data) { return data; },
queueRunnerFactory: function(attrs) { attrs.onComplete(); },
@@ -291,7 +291,7 @@ describe("Spec", function() {
it("can return its full name", function() {
var specNameSpy = jasmine.createSpy('specNameSpy').and.returnValue('expected val');
var spec = new j$.Spec({
var spec = new jasmineUnderTest.Spec({
getSpecName: specNameSpy,
queueableFn: { fn: null }
});
@@ -303,9 +303,9 @@ describe("Spec", function() {
describe("when a spec is marked pending during execution", function() {
it("should mark the spec as pending", function() {
var fakeQueueRunner = function(opts) {
opts.onException(new Error(j$.Spec.pendingSpecExceptionMessage));
opts.onException(new Error(jasmineUnderTest.Spec.pendingSpecExceptionMessage));
},
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
description: 'my test',
id: 'some-id',
queueableFn: { fn: function() { } },
@@ -320,9 +320,9 @@ describe("Spec", function() {
it("should set the pendingReason", function() {
var fakeQueueRunner = function(opts) {
opts.onException(new Error(j$.Spec.pendingSpecExceptionMessage + 'custom message'));
opts.onException(new Error(jasmineUnderTest.Spec.pendingSpecExceptionMessage + 'custom message'));
},
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
description: 'my test',
id: 'some-id',
queueableFn: { fn: function() { } },
@@ -338,7 +338,7 @@ describe("Spec", function() {
it("should log a failure when handling an exception", function() {
var resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
queueableFn: { fn: function() {} },
expectationResultFactory: function(data) { return data; },
queueRunnerFactory: function(attrs) { attrs.onComplete(); },
@@ -359,41 +359,41 @@ describe("Spec", function() {
it("should not log an additional failure when handling an ExpectationFailed error", function() {
var resultCallback = jasmine.createSpy('resultCallback'),
spec = new j$.Spec({
spec = new jasmineUnderTest.Spec({
queueableFn: { fn: function() {} },
expectationResultFactory: function(data) { return data; },
queueRunnerFactory: function(attrs) { attrs.onComplete(); },
resultCallback: resultCallback
});
spec.onException(new j$.errors.ExpectationFailed());
spec.onException(new jasmineUnderTest.errors.ExpectationFailed());
spec.execute();
expect(resultCallback.calls.first().args[0].failedExpectations).toEqual([]);
});
it("retrieves a result with updated status", function() {
var spec = new j$.Spec({ queueableFn: { fn: function() {} } });
var spec = new jasmineUnderTest.Spec({ queueableFn: { fn: function() {} } });
expect(spec.getResult().status).toBe('passed');
});
it("retrives a result with disabled status", function() {
var spec = new j$.Spec({ queueableFn: { fn: function() {} } });
var spec = new jasmineUnderTest.Spec({ queueableFn: { fn: function() {} } });
spec.disable();
expect(spec.getResult().status).toBe('disabled');
});
it("retrives a result with pending status", function() {
var spec = new j$.Spec({ queueableFn: { fn: function() {} } });
var spec = new jasmineUnderTest.Spec({ queueableFn: { fn: function() {} } });
spec.pend();
expect(spec.getResult().status).toBe('pending');
});
it("should not be executable when disabled", function() {
var spec = new j$.Spec({
var spec = new jasmineUnderTest.Spec({
queueableFn: { fn: function() {} }
});
spec.disable();
@@ -402,7 +402,7 @@ describe("Spec", function() {
});
it("should be executable when pending", function() {
var spec = new j$.Spec({
var spec = new jasmineUnderTest.Spec({
queueableFn: { fn: function() {} }
});
spec.pend();
@@ -411,7 +411,7 @@ describe("Spec", function() {
});
it("should be executable when not disabled or pending", function() {
var spec = new j$.Spec({
var spec = new jasmineUnderTest.Spec({
queueableFn: { fn: function() {} }
});

View File

@@ -1,14 +1,14 @@
describe("SpyRegistry", function() {
describe("#spyOn", function() {
it("checks for the existence of the object", function() {
var spyRegistry = new j$.SpyRegistry();
var spyRegistry = new jasmineUnderTest.SpyRegistry();
expect(function() {
spyRegistry.spyOn(void 0, 'pants');
}).toThrowError(/could not find an object/);
});
it("checks that a method name was passed", function() {
var spyRegistry = new j$.SpyRegistry(),
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {};
expect(function() {
@@ -16,8 +16,24 @@ describe("SpyRegistry", function() {
}).toThrowError(/No method name supplied/);
});
it("checks that the object is not `null`", function() {
var spyRegistry = new jasmineUnderTest.SpyRegistry();
expect(function() {
spyRegistry.spyOn(null, 'pants');
}).toThrowError(/could not find an object/);
});
it("checks that the method name is not `null`", function() {
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {};
expect(function() {
spyRegistry.spyOn(subject, null);
}).toThrowError(/No method name supplied/);
});
it("checks for the existence of the method", function() {
var spyRegistry = new j$.SpyRegistry(),
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {};
expect(function() {
@@ -27,7 +43,7 @@ describe("SpyRegistry", function() {
it("checks if it has already been spied upon", function() {
var spies = [],
spyRegistry = new j$.SpyRegistry({currentSpies: function() { return spies; }}),
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
subject = { spiedFunc: function() {} };
spyRegistry.spyOn(subject, 'spiedFunc');
@@ -54,7 +70,7 @@ describe("SpyRegistry", function() {
});
var spies = [],
spyRegistry = new j$.SpyRegistry({currentSpies: function() { return spies; }}),
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
subject = { spiedFunc: scope.myFunc };
expect(function() {
@@ -68,7 +84,7 @@ describe("SpyRegistry", function() {
it("overrides the method on the object and returns the spy", function() {
var originalFunctionWasCalled = false,
spyRegistry = new j$.SpyRegistry(),
spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
var spy = spyRegistry.spyOn(subject, 'spiedFunc');
@@ -77,10 +93,130 @@ describe("SpyRegistry", function() {
});
});
describe("#spyOnProperty", function() {
// IE 8 doesn't support `definePropery` on non-DOM nodes
if (jasmine.getEnv().ieVersion < 9) { return; }
it("checks for the existence of the object", function() {
var spyRegistry = new jasmineUnderTest.SpyRegistry();
expect(function() {
spyRegistry.spyOnProperty(void 0, 'pants');
}).toThrowError(/could not find an object/);
});
it("checks that a property name was passed", function() {
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {};
expect(function() {
spyRegistry.spyOnProperty(subject);
}).toThrowError(/No property name supplied/);
});
it("checks for the existence of the method", function() {
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {};
expect(function() {
spyRegistry.spyOnProperty(subject, 'pants');
}).toThrowError(/property does not exist/);
});
it("checks for the existence of access type", function() {
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {};
Object.defineProperty(subject, 'pants', {
get: function() { return 1; },
configurable: true
});
expect(function() {
spyRegistry.spyOnProperty(subject, 'pants', 'set');
}).toThrowError(/does not have access type/);
});
it("checks if it has already been spied upon", function() {
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {};
Object.defineProperty(subject, 'spiedProp', {
get: function() { return 1; },
configurable: true
});
spyRegistry.spyOnProperty(subject, 'spiedProp');
expect(function() {
spyRegistry.spyOnProperty(subject, 'spiedProp');
}).toThrowError(/has already been spied upon/);
});
it("checks if it can be spied upon", function() {
var subject = {};
Object.defineProperty(subject, 'myProp', {
get: function() {}
});
Object.defineProperty(subject, 'spiedProp', {
get: function() {},
configurable: true
});
var spyRegistry = new jasmineUnderTest.SpyRegistry();
expect(function() {
spyRegistry.spyOnProperty(subject, 'myProp');
}).toThrowError(/is not declared configurable/);
expect(function() {
spyRegistry.spyOnProperty(subject, 'spiedProp');
}).not.toThrowError(/is not declared configurable/);
});
it("overrides the property getter on the object and returns the spy", function() {
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {},
returnValue = 1;
Object.defineProperty(subject, 'spiedProperty', {
get: function() { return returnValue; },
configurable: true
});
expect(subject.spiedProperty).toEqual(returnValue);
var spy = spyRegistry.spyOnProperty(subject, 'spiedProperty');
var getter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty').get;
expect(getter).toEqual(spy);
expect(subject.spiedProperty).toBeUndefined();
});
it("overrides the property setter on the object and returns the spy", function() {
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
subject = {},
returnValue = 1;
Object.defineProperty(subject, 'spiedProperty', {
get: function() { return returnValue; },
set: function() {},
configurable: true
});
var spy = spyRegistry.spyOnProperty(subject, 'spiedProperty', 'set');
var setter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty').set;
expect(subject.spiedProperty).toEqual(returnValue);
expect(setter).toEqual(spy);
});
});
describe("#clearSpies", function() {
it("restores the original functions on the spied-upon objects", function() {
var spies = [],
spyRegistry = new j$.SpyRegistry({currentSpies: function() { return spies; }}),
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
originalFunction = function() {},
subject = { spiedFunc: originalFunction };
@@ -89,5 +225,114 @@ describe("SpyRegistry", function() {
expect(subject.spiedFunc).toBe(originalFunction);
});
it("restores the original functions, even when that spy has been replace and re-spied upon", function() {
var spies = [],
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
originalFunction = function() {},
subject = { spiedFunc: originalFunction };
spyRegistry.spyOn(subject, 'spiedFunc');
// replace the original spy with some other function
subject.spiedFunc = function() {};
// spy on the function in that location again
spyRegistry.spyOn(subject, 'spiedFunc');
spyRegistry.clearSpies();
expect(subject.spiedFunc).toBe(originalFunction);
});
it("does not add a property that the spied-upon object didn't originally have", function() {
// IE 8 doesn't support `Object.create`
if (jasmine.getEnv().ieVersion < 9) { return; }
var spies = [],
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
originalFunction = function() {},
subjectParent = {spiedFunc: originalFunction};
var subject = Object.create(subjectParent);
expect(subject.hasOwnProperty('spiedFunc')).toBe(false);
spyRegistry.spyOn(subject, 'spiedFunc');
spyRegistry.clearSpies();
expect(subject.hasOwnProperty('spiedFunc')).toBe(false);
expect(subject.spiedFunc).toBe(originalFunction);
});
it("restores the original function when it\'s inherited and cannot be deleted", function() {
// IE 8 doesn't support `Object.create` or `Object.defineProperty`
if (jasmine.getEnv().ieVersion < 9) { return; }
var spies = [],
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
originalFunction = function() {},
subjectParent = {spiedFunc: originalFunction};
var subject = Object.create(subjectParent);
spyRegistry.spyOn(subject, 'spiedFunc');
// simulate a spy that cannot be deleted
Object.defineProperty(subject, 'spiedFunc', {
configurable: false
});
spyRegistry.clearSpies();
expect(jasmineUnderTest.isSpy(subject.spiedFunc)).toBe(false);
});
});
describe('spying on properties', function() {
it("restores the original properties on the spied-upon objects", function() {
// IE 8 doesn't support `definePropery` on non-DOM nodes
if (jasmine.getEnv().ieVersion < 9) { return; }
var spies = [],
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
originalReturn = 1,
subject = {};
Object.defineProperty(subject, 'spiedProp', {
get: function() { return originalReturn; },
configurable: true
});
spyRegistry.spyOnProperty(subject, 'spiedProp');
spyRegistry.clearSpies();
expect(subject.spiedProp).toBe(originalReturn);
});
it("does not add a property that the spied-upon object didn't originally have", function() {
// IE 8 doesn't support `Object.create`
if (jasmine.getEnv().ieVersion < 9) { return; }
var spies = [],
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
originalReturn = 1,
subjectParent = {};
Object.defineProperty(subjectParent, 'spiedProp', {
get: function() { return originalReturn; },
configurable: true
});
var subject = Object.create(subjectParent);
expect(subject.hasOwnProperty('spiedProp')).toBe(false);
spyRegistry.spyOnProperty(subject, 'spiedProp');
spyRegistry.clearSpies();
expect(subject.hasOwnProperty('spiedProp')).toBe(false);
expect(subject.spiedProp).toBe(originalReturn);
});
});
});

View File

@@ -9,7 +9,7 @@ describe('Spies', function () {
});
it("preserves the properties of the spied function", function() {
var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
expect(spy.bob).toEqual("test");
});
@@ -18,19 +18,19 @@ describe('Spies', function () {
TestClass.prototype.someFunction.and = "turkey";
expect(function() {
j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
}).toThrowError("Jasmine spies would overwrite the 'and' and 'calls' properties on the object being spied upon");
});
it("adds a spyStrategy and callTracker to the spy", function() {
var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
expect(spy.and).toEqual(jasmine.any(j$.SpyStrategy));
expect(spy.calls).toEqual(jasmine.any(j$.CallTracker));
expect(spy.and).toEqual(jasmine.any(jasmineUnderTest.SpyStrategy));
expect(spy.calls).toEqual(jasmine.any(jasmineUnderTest.CallTracker));
});
it("tracks the argument of calls", function () {
var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
var trackSpy = spyOn(spy.calls, "track");
spy("arg");
@@ -39,7 +39,7 @@ describe('Spies', function () {
});
it("tracks the context of calls", function () {
var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
var trackSpy = spyOn(spy.calls, "track");
var contextObject = { spyMethod: spy };
@@ -49,7 +49,7 @@ describe('Spies', function () {
});
it("tracks the return value of calls", function () {
var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
var spy = jasmineUnderTest.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
var trackSpy = spyOn(spy.calls, "track");
spy.and.returnValue("return value");
@@ -57,11 +57,41 @@ describe('Spies', function () {
expect(trackSpy.calls.mostRecent().args[0].returnValue).toEqual("return value");
});
it("preserves arity of original function", function () {
var functions = [
function nullary () {},
function unary (arg) {},
function binary (arg1, arg2) {},
function ternary (arg1, arg2, arg3) {},
function quaternary (arg1, arg2, arg3, arg4) {},
function quinary (arg1, arg2, arg3, arg4, arg5) {},
function senary (arg1, arg2, arg3, arg4, arg5, arg6) {}
];
for (var arity = 0; arity < functions.length; arity++) {
var someFunction = functions[arity],
spy = jasmineUnderTest.createSpy(someFunction.name, someFunction);
expect(spy.length).toEqual(arity);
}
});
});
describe("createSpyObj", function() {
it("should create an object with spy methods and corresponding return values when you call jasmine.createSpyObj() with an object", function () {
var spyObj = jasmineUnderTest.createSpyObj('BaseName', {'method1': 42, 'method2': 'special sauce' });
expect(spyObj.method1()).toEqual(42);
expect(spyObj.method1.and.identity()).toEqual('BaseName.method1');
expect(spyObj.method2()).toEqual('special sauce');
expect(spyObj.method2.and.identity()).toEqual('BaseName.method2');
});
it("should create an object with a bunch of spy methods when you call jasmine.createSpyObj()", function() {
var spyObj = j$.createSpyObj('BaseName', ['method1', 'method2']);
var spyObj = jasmineUnderTest.createSpyObj('BaseName', ['method1', 'method2']);
expect(spyObj).toEqual({ method1: jasmine.any(Function), method2: jasmine.any(Function)});
expect(spyObj.method1.and.identity()).toEqual('BaseName.method1');
@@ -69,17 +99,29 @@ describe('Spies', function () {
});
it("should allow you to omit the baseName", function() {
var spyObj = j$.createSpyObj(['method1', 'method2']);
var spyObj = jasmineUnderTest.createSpyObj(['method1', 'method2']);
expect(spyObj).toEqual({ method1: jasmine.any(Function), method2: jasmine.any(Function)});
expect(spyObj.method1.and.identity()).toEqual('unknown.method1');
expect(spyObj.method2.and.identity()).toEqual('unknown.method2');
});
it("should throw if you do not pass an array argument", function() {
it("should throw if you do not pass an array or object argument", function() {
expect(function() {
j$.createSpyObj('BaseName');
}).toThrow("createSpyObj requires a non-empty array of method names to create spies for");
jasmineUnderTest.createSpyObj('BaseName');
}).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
});
it("should throw if you pass an empty array argument", function() {
expect(function() {
jasmineUnderTest.createSpyObj('BaseName', []);
}).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
});
it("should throw if you pass an empty object argument", function() {
expect(function() {
jasmineUnderTest.createSpyObj('BaseName', {});
}).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
});
});
});

View File

@@ -1,20 +1,20 @@
describe("SpyStrategy", function() {
it("defaults its name to unknown", function() {
var spyStrategy = new j$.SpyStrategy();
var spyStrategy = new jasmineUnderTest.SpyStrategy();
expect(spyStrategy.identity()).toEqual("unknown");
});
it("takes a name", function() {
var spyStrategy = new j$.SpyStrategy({name: "foo"});
var spyStrategy = new jasmineUnderTest.SpyStrategy({name: "foo"});
expect(spyStrategy.identity()).toEqual("foo");
});
it("stubs an original function, if provided", function() {
var originalFn = jasmine.createSpy("original"),
spyStrategy = new j$.SpyStrategy({fn: originalFn});
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn});
spyStrategy.exec();
@@ -23,7 +23,7 @@ describe("SpyStrategy", function() {
it("allows an original function to be called, passed through the params and returns it's value", function() {
var originalFn = jasmine.createSpy("original").and.returnValue(42),
spyStrategy = new j$.SpyStrategy({fn: originalFn}),
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
returnValue;
spyStrategy.callThrough();
@@ -36,7 +36,7 @@ describe("SpyStrategy", function() {
it("can return a specified value when executed", function() {
var originalFn = jasmine.createSpy("original"),
spyStrategy = new j$.SpyStrategy({fn: originalFn}),
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
returnValue;
spyStrategy.returnValue(17);
@@ -48,7 +48,7 @@ describe("SpyStrategy", function() {
it("can return specified values in order specified when executed", function() {
var originalFn = jasmine.createSpy("original"),
spyStrategy = new j$.SpyStrategy({fn: originalFn});
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn});
spyStrategy.returnValues('value1', 'value2', 'value3');
@@ -61,7 +61,7 @@ describe("SpyStrategy", function() {
it("allows an exception to be thrown when executed", function() {
var originalFn = jasmine.createSpy("original"),
spyStrategy = new j$.SpyStrategy({fn: originalFn});
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn});
spyStrategy.throwError(new TypeError("bar"));
@@ -71,7 +71,7 @@ describe("SpyStrategy", function() {
it("allows a non-Error to be thrown, wrapping it into an exception when executed", function() {
var originalFn = jasmine.createSpy("original"),
spyStrategy = new j$.SpyStrategy({fn: originalFn});
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn});
spyStrategy.throwError("bar");
@@ -82,7 +82,7 @@ describe("SpyStrategy", function() {
it("allows a fake function to be called instead", function() {
var originalFn = jasmine.createSpy("original"),
fakeFn = jasmine.createSpy("fake").and.returnValue(67),
spyStrategy = new j$.SpyStrategy({fn: originalFn}),
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
returnValue;
spyStrategy.callFake(fakeFn);
@@ -92,10 +92,22 @@ describe("SpyStrategy", function() {
expect(returnValue).toEqual(67);
});
it('throws an error when a non-function is passed to callFake strategy', function() {
var originalFn = jasmine.createSpy('original'),
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
invalidFakes = [5, 'foo', {}, true, false, null, void 0, new Date(), /.*/];
spyOn(jasmineUnderTest, 'isFunction_').and.returnValue(false);
expect(function () {
spyStrategy.callFake(function() {});
}).toThrowError(/^Argument passed to callFake should be a function, got/);
});
it("allows a return to plan stubbing after another strategy", function() {
var originalFn = jasmine.createSpy("original"),
fakeFn = jasmine.createSpy("fake").and.returnValue(67),
spyStrategy = new j$.SpyStrategy({fn: originalFn}),
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
returnValue;
spyStrategy.callFake(fakeFn);
@@ -103,7 +115,7 @@ describe("SpyStrategy", function() {
expect(originalFn).not.toHaveBeenCalled();
expect(returnValue).toEqual(67);
spyStrategy.stub();
returnValue = spyStrategy.exec();
@@ -113,12 +125,12 @@ describe("SpyStrategy", function() {
it("returns the spy after changing the strategy", function(){
var spy = {},
spyFn = jasmine.createSpy('spyFn').and.returnValue(spy),
spyStrategy = new j$.SpyStrategy({getSpy: spyFn});
spyStrategy = new jasmineUnderTest.SpyStrategy({getSpy: spyFn});
expect(spyStrategy.callThrough()).toBe(spy);
expect(spyStrategy.returnValue()).toBe(spy);
expect(spyStrategy.throwError()).toBe(spy);
expect(spyStrategy.callFake()).toBe(spy);
expect(spyStrategy.callFake(function() {})).toBe(spy);
expect(spyStrategy.stub()).toBe(spy);
});
});

View File

@@ -1,8 +1,8 @@
describe("Suite", function() {
it("keeps its id", function() {
var env = new j$.Env(),
suite = new j$.Suite({
var env = new jasmineUnderTest.Env(),
suite = new jasmineUnderTest.Suite({
env: env,
id: 456,
description: "I am a suite"
@@ -11,24 +11,24 @@ describe("Suite", function() {
expect(suite.id).toEqual(456);
});
it("returns its full name", function() {
var env = new j$.Env(),
suite = new j$.Suite({
it("returns blank full name for top level suite", function() {
var env = new jasmineUnderTest.Env(),
suite = new jasmineUnderTest.Suite({
env: env,
description: "I am a suite"
});
expect(suite.getFullName()).toEqual("I am a suite");
expect(suite.getFullName()).toEqual("");
});
it("returns its full name when it has parent suites", function() {
var env = new j$.Env(),
parentSuite = new j$.Suite({
var env = new jasmineUnderTest.Env(),
parentSuite = new jasmineUnderTest.Suite({
env: env,
description: "I am a parent suite",
parentSuite: jasmine.createSpy('pretend top level suite')
}),
suite = new j$.Suite({
suite = new jasmineUnderTest.Suite({
env: env,
description: "I am a suite",
parentSuite: parentSuite
@@ -38,8 +38,8 @@ describe("Suite", function() {
});
it("adds before functions in order of needed execution", function() {
var env = new j$.Env(),
suite = new j$.Suite({
var env = new jasmineUnderTest.Env(),
suite = new jasmineUnderTest.Suite({
env: env,
description: "I am a suite"
}),
@@ -53,8 +53,8 @@ describe("Suite", function() {
});
it("adds after functions in order of needed execution", function() {
var env = new j$.Env(),
suite = new j$.Suite({
var env = new jasmineUnderTest.Env(),
suite = new jasmineUnderTest.Suite({
env: env,
description: "I am a suite"
}),
@@ -68,7 +68,7 @@ describe("Suite", function() {
});
it('has a status of failed if any afterAll expectations have failed', function() {
var suite = new j$.Suite({
var suite = new jasmineUnderTest.Suite({
expectationResultFactory: function() { return 'hi'; }
});
suite.addChild({ result: { status: 'done' } });
@@ -78,48 +78,33 @@ describe("Suite", function() {
});
it("retrieves a result with updated status", function() {
var suite = new j$.Suite({});
var suite = new jasmineUnderTest.Suite({});
expect(suite.getResult().status).toBe('finished');
});
it("retrieves a result with disabled status", function() {
var suite = new j$.Suite({});
suite.disable();
expect(suite.getResult().status).toBe('disabled');
});
it("retrieves a result with pending status", function() {
var suite = new j$.Suite({});
var suite = new jasmineUnderTest.Suite({});
suite.pend();
expect(suite.getResult().status).toBe('pending');
});
it("priviledges a disabled status over pending status", function() {
var suite = new j$.Suite({});
suite.disable();
suite.pend();
expect(suite.getResult().status).toBe('disabled');
});
it("is executable if not disabled", function() {
var suite = new j$.Suite({});
it("is executable if not pending", function() {
var suite = new jasmineUnderTest.Suite({});
expect(suite.isExecutable()).toBe(true);
});
it("is not executable if disabled", function() {
var suite = new j$.Suite({});
suite.disable();
it("is not executable if pending", function() {
var suite = new jasmineUnderTest.Suite({});
suite.pend();
expect(suite.isExecutable()).toBe(false);
});
it("tells all children about expectation failures, even if one throws", function() {
var suite = new j$.Suite({}),
var suite = new jasmineUnderTest.Suite({}),
child1 = { addExpectationResult: jasmine.createSpy('child1#expectationResult'), result: {} },
child2 = { addExpectationResult: jasmine.createSpy('child2#expectationResult'), result: {} };
@@ -135,7 +120,7 @@ describe("Suite", function() {
});
it("throws an ExpectationFailed when receiving a failed expectation in an afterAll when throwOnExpectationFailure is set", function() {
var suite = new j$.Suite({
var suite = new jasmineUnderTest.Suite({
expectationResultFactory: function(data) { return data; },
throwOnExpectationFailure: true
});
@@ -143,17 +128,17 @@ describe("Suite", function() {
expect(function() {
suite.addExpectationResult(false, 'failed');
}).toThrowError(j$.errors.ExpectationFailed);
}).toThrowError(jasmineUnderTest.errors.ExpectationFailed);
expect(suite.status()).toBe('failed');
expect(suite.result.failedExpectations).toEqual(['failed']);
});
it("does not add an additional failure when an expectation fails in an afterAll", function(){
var suite = new j$.Suite({});
var suite = new jasmineUnderTest.Suite({});
suite.addChild({ result: { status: 'done' } });
suite.onException(new j$.errors.ExpectationFailed());
suite.onException(new jasmineUnderTest.errors.ExpectationFailed());
expect(suite.getResult().failedExpectations).toEqual([]);
})

View File

@@ -1,7 +1,7 @@
describe("Timer", function() {
it("reports the time elapsed", function() {
var fakeNow = jasmine.createSpy('fake Date.now'),
timer = new j$.Timer({now: fakeNow});
timer = new jasmineUnderTest.Timer({now: fakeNow});
fakeNow.and.returnValue(100);
timer.start();
@@ -22,7 +22,7 @@ describe("Timer", function() {
});
it("does not throw even though Date was taken away", function() {
var timer = new j$.Timer();
var timer = new jasmineUnderTest.Timer();
expect(timer.start).not.toThrow();
expect(timer.elapsed()).toEqual(jasmine.any(Number));

View File

@@ -30,7 +30,7 @@ describe("TreeProcessor", function() {
it("processes a single executable leaf", function() {
var leaf = new Leaf(),
processor = new j$.TreeProcessor({ tree: leaf, runnableIds: [leaf.id] }),
processor = new jasmineUnderTest.TreeProcessor({ tree: leaf, runnableIds: [leaf.id] }),
result = processor.processTree();
expect(result.valid).toBe(true);
@@ -43,7 +43,7 @@ describe("TreeProcessor", function() {
it("processes a single non-executable leaf", function() {
var leaf = new Leaf({ executable: false }),
processor = new j$.TreeProcessor({ tree: leaf, runnableIds: [leaf.id] }),
processor = new jasmineUnderTest.TreeProcessor({ tree: leaf, runnableIds: [leaf.id] }),
result = processor.processTree();
expect(result.valid).toBe(true);
@@ -56,7 +56,7 @@ describe("TreeProcessor", function() {
it("processes a single non-specified leaf", function() {
var leaf = new Leaf(),
processor = new j$.TreeProcessor({ tree: leaf, runnableIds: [] }),
processor = new jasmineUnderTest.TreeProcessor({ tree: leaf, runnableIds: [] }),
result = processor.processTree();
expect(result.valid).toBe(true);
@@ -70,7 +70,7 @@ describe("TreeProcessor", function() {
it("processes a tree with a single leaf with the root specified", function() {
var leaf = new Leaf(),
parent = new Node({ children: [leaf] }),
processor = new j$.TreeProcessor({ tree: parent, runnableIds: [parent.id] }),
processor = new jasmineUnderTest.TreeProcessor({ tree: parent, runnableIds: [parent.id] }),
result = processor.processTree();
expect(result.valid).toBe(true);
@@ -89,7 +89,7 @@ describe("TreeProcessor", function() {
it("processes a tree with a single non-executable leaf, with the root specified", function() {
var leaf = new Leaf({ executable: false }),
parent = new Node({ children: [leaf] }),
processor = new j$.TreeProcessor({ tree: parent, runnableIds: [parent.id] }),
processor = new jasmineUnderTest.TreeProcessor({ tree: parent, runnableIds: [parent.id] }),
result = processor.processTree();
expect(result.valid).toBe(true);
@@ -113,7 +113,7 @@ describe("TreeProcessor", function() {
childOfDisabled = new Leaf({ executable: true }),
disabledNode = new Node({ executable: false, children: [childOfDisabled] }),
root = new Node({ children: [parent, childless, disabledNode] }),
processor = new j$.TreeProcessor({ tree: root, runnableIds: [root.id] }),
processor = new jasmineUnderTest.TreeProcessor({ tree: root, runnableIds: [root.id] }),
result = processor.processTree();
expect(result.valid).toBe(true);
@@ -160,7 +160,7 @@ describe("TreeProcessor", function() {
leaf3 = new Leaf(),
reentered = new Node({ noReenter: true, children: [leaf1, leaf2] }),
root = new Node({ children: [reentered, leaf3] }),
processor = new j$.TreeProcessor({ tree: root, runnableIds: [leaf1.id, leaf3.id, leaf2.id] }),
processor = new jasmineUnderTest.TreeProcessor({ tree: root, runnableIds: [leaf1.id, leaf3.id, leaf2.id] }),
result = processor.processTree();
expect(result).toEqual({ valid: false });
@@ -172,7 +172,7 @@ describe("TreeProcessor", function() {
leaf3 = new Leaf(),
reentered = new Node({ children: [leaf1, leaf2] }),
root = new Node({ children: [reentered, leaf3] }),
processor = new j$.TreeProcessor({ tree: root, runnableIds: [leaf1.id, leaf3.id, leaf2.id] }),
processor = new jasmineUnderTest.TreeProcessor({ tree: root, runnableIds: [leaf1.id, leaf3.id, leaf2.id] }),
result = processor.processTree();
expect(result.valid).toBe(true);
@@ -184,7 +184,7 @@ describe("TreeProcessor", function() {
leaf3 = new Leaf(),
noReentry = new Node({ noReenter: true }),
root = new Node({ children: [noReentry] }),
processor = new j$.TreeProcessor({ tree: root, runnableIds: [leaf2.id, leaf1.id, leaf3.id] }),
processor = new jasmineUnderTest.TreeProcessor({ tree: root, runnableIds: [leaf2.id, leaf1.id, leaf3.id] }),
result = processor.processTree();
expect(result.valid).toBe(true);
@@ -194,7 +194,7 @@ describe("TreeProcessor", function() {
var leaf1 = new Leaf(),
noReentry = new Node({ noReenter: true }),
root = new Node({ children: [noReentry] }),
processor = new j$.TreeProcessor({ tree: root, runnableIds: [root.id] }),
processor = new jasmineUnderTest.TreeProcessor({ tree: root, runnableIds: [root.id] }),
result = processor.processTree();
expect(result.valid).toBe(true);
@@ -204,7 +204,7 @@ describe("TreeProcessor", function() {
var leaf = new Leaf(),
node = new Node({ children: [leaf], userContext: { root: 'context' } }),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({ tree: node, runnableIds: [leaf.id], queueRunnerFactory: queueRunner }),
processor = new jasmineUnderTest.TreeProcessor({ tree: node, runnableIds: [leaf.id], queueRunnerFactory: queueRunner }),
treeComplete = jasmine.createSpy('treeComplete');
processor.execute(treeComplete);
@@ -227,7 +227,7 @@ describe("TreeProcessor", function() {
nodeStart = jasmine.createSpy('nodeStart'),
nodeComplete = jasmine.createSpy('nodeComplete'),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [node.id],
nodeStart: nodeStart,
@@ -269,7 +269,7 @@ describe("TreeProcessor", function() {
node = new Node({ children: [leaf1, leaf2] }),
root = new Node({ children: [node] }),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [node.id],
queueRunnerFactory: queueRunner
@@ -298,7 +298,7 @@ describe("TreeProcessor", function() {
queueRunner = jasmine.createSpy('queueRunner'),
nodeStart = jasmine.createSpy('nodeStart'),
nodeComplete = jasmine.createSpy('nodeComplete'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [node.id],
queueRunnerFactory: queueRunner,
@@ -334,7 +334,7 @@ describe("TreeProcessor", function() {
}),
root = new Node({ children: [node] }),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [node.id],
queueRunnerFactory: queueRunner
@@ -359,7 +359,7 @@ describe("TreeProcessor", function() {
}),
root = new Node({ children: [node] }),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [node.id],
queueRunnerFactory: queueRunner
@@ -383,7 +383,7 @@ describe("TreeProcessor", function() {
}),
root = new Node({ children: [node] }),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [node.id],
queueRunnerFactory: queueRunner
@@ -410,7 +410,7 @@ describe("TreeProcessor", function() {
}),
root = new Node({ children: [node] }),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [node.id],
queueRunnerFactory: queueRunner
@@ -432,7 +432,7 @@ describe("TreeProcessor", function() {
leaf2 = new Leaf(),
root = new Node({ children: [leaf1, leaf2] }),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [leaf2.id, leaf1.id],
queueRunnerFactory: queueRunner
@@ -456,7 +456,7 @@ describe("TreeProcessor", function() {
nonSpecified = new Leaf(),
root = new Node({ children: [nonSpecified, specified] }),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [specified.id],
queueRunnerFactory: queueRunner
@@ -481,7 +481,7 @@ describe("TreeProcessor", function() {
specifiedNode = new Node({ children: [childLeaf] }),
root = new Node({ children: [specifiedLeaf, specifiedNode] }),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [specifiedNode.id, specifiedLeaf.id],
queueRunnerFactory: queueRunner
@@ -511,7 +511,7 @@ describe("TreeProcessor", function() {
reentered = new Node({ children: [leaf1, leaf2, leaf3] }),
root = new Node({ children: [reentered, leaf4, leaf5] }),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [leaf1.id, leaf4.id, leaf2.id, leaf5.id, leaf3.id],
queueRunnerFactory: queueRunner
@@ -555,7 +555,7 @@ describe("TreeProcessor", function() {
grandparent = new Node({ children: [parent] }),
root = new Node({ children: [grandparent, leaf4, leaf5] }),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [leaf1.id, leaf4.id, leaf2.id, leaf5.id, leaf3.id],
queueRunnerFactory: queueRunner
@@ -609,7 +609,7 @@ describe("TreeProcessor", function() {
parent = new Node({ children: [leaf2, leaf3] }),
root = new Node({ children: [leaf1, parent] }),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [root.id],
queueRunnerFactory: queueRunner
@@ -647,7 +647,7 @@ describe("TreeProcessor", function() {
leaf11 = new Leaf(),
root = new Node({ children: [leaf1, leaf2, leaf3, leaf4, leaf5, leaf6, leaf7, leaf8, leaf9, leaf10, leaf11] }),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [root.id],
queueRunnerFactory: queueRunner
@@ -705,7 +705,7 @@ describe("TreeProcessor", function() {
leaf11 = new Leaf(),
root = new Node({ children: [leaf1, leaf2, leaf3, leaf4, leaf5, leaf6, leaf7, leaf8, leaf9, leaf10, leaf11] }),
queueRunner = jasmine.createSpy('queueRunner'),
processor = new j$.TreeProcessor({
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [root.id],
queueRunnerFactory: queueRunner,

View File

@@ -1,28 +1,99 @@
describe("j$.util", function() {
describe("jasmineUnderTest.util", function() {
describe("isArray_", function() {
it("should return true if the argument is an array", function() {
expect(j$.isArray_([])).toBe(true);
expect(j$.isArray_(['a'])).toBe(true);
expect(jasmineUnderTest.isArray_([])).toBe(true);
expect(jasmineUnderTest.isArray_(['a'])).toBe(true);
});
it("should return false if the argument is not an array", function() {
expect(j$.isArray_(undefined)).toBe(false);
expect(j$.isArray_({})).toBe(false);
expect(j$.isArray_(function() {})).toBe(false);
expect(j$.isArray_('foo')).toBe(false);
expect(j$.isArray_(5)).toBe(false);
expect(j$.isArray_(null)).toBe(false);
expect(jasmineUnderTest.isArray_(undefined)).toBe(false);
expect(jasmineUnderTest.isArray_({})).toBe(false);
expect(jasmineUnderTest.isArray_(function() {})).toBe(false);
expect(jasmineUnderTest.isArray_('foo')).toBe(false);
expect(jasmineUnderTest.isArray_(5)).toBe(false);
expect(jasmineUnderTest.isArray_(null)).toBe(false);
});
});
describe("isObject_", function() {
it("should return true if the argument is an object", function() {
expect(jasmineUnderTest.isObject_({})).toBe(true);
expect(jasmineUnderTest.isObject_({an: "object"})).toBe(true);
});
it("should return false if the argument is not an object", function() {
expect(jasmineUnderTest.isObject_(undefined)).toBe(false);
expect(jasmineUnderTest.isObject_([])).toBe(false);
expect(jasmineUnderTest.isObject_(function() {})).toBe(false);
expect(jasmineUnderTest.isObject_('foo')).toBe(false);
expect(jasmineUnderTest.isObject_(5)).toBe(false);
expect(jasmineUnderTest.isObject_(null)).toBe(false);
});
});
describe("isUndefined", function() {
it("reports if a variable is defined", function() {
var a;
expect(j$.util.isUndefined(a)).toBe(true);
expect(j$.util.isUndefined(undefined)).toBe(true);
expect(jasmineUnderTest.util.isUndefined(a)).toBe(true);
expect(jasmineUnderTest.util.isUndefined(undefined)).toBe(true);
var undefined = "diz be undefined yo";
expect(j$.util.isUndefined(undefined)).toBe(false);
expect(jasmineUnderTest.util.isUndefined(undefined)).toBe(false);
});
});
describe("getPropertyDescriptor", function() {
// IE 8 doesn't support `definePropery` on non-DOM nodes
if (jasmine.getEnv().ieVersion < 9) { return; }
it("get property descriptor from object", function() {
var obj = {prop: 1},
actual = jasmineUnderTest.util.getPropertyDescriptor(obj, 'prop'),
expected = Object.getOwnPropertyDescriptor(obj, 'prop');
expect(actual).toEqual(expected);
});
it("get property descriptor from object property", function() {
var proto = {prop: 1},
obj = Object.create(proto),
actual = jasmineUnderTest.util.getPropertyDescriptor(proto, 'prop'),
expected = Object.getOwnPropertyDescriptor(proto, 'prop');
expect(actual).toEqual(expected);
});
});
describe("objectDifference", function() {
it("given two objects A and B, returns the properties in A not present in B", function() {
var a = {
foo: 3,
bar: 4,
baz: 5
};
var b = {
bar: 6,
quux: 7
};
expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual({foo: 3, baz: 5})
});
it("only looks at own properties of both objects", function() {
function Foo() {}
Foo.prototype.x = 1;
Foo.prototype.y = 2;
var a = new Foo();
a.x = 1;
var b = new Foo();
b.y = 2;
expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual({x: 1});
expect(jasmineUnderTest.util.objectDifference(b, a)).toEqual({y: 2});
})
})
});

View File

@@ -1,43 +1,43 @@
describe("Any", function() {
it("matches a string", function() {
var any = new j$.Any(String);
var any = new jasmineUnderTest.Any(String);
expect(any.asymmetricMatch("foo")).toBe(true);
});
it("matches a number", function() {
var any = new j$.Any(Number);
var any = new jasmineUnderTest.Any(Number);
expect(any.asymmetricMatch(1)).toBe(true);
});
it("matches a function", function() {
var any = new j$.Any(Function);
var any = new jasmineUnderTest.Any(Function);
expect(any.asymmetricMatch(function(){})).toBe(true);
});
it("matches an Object", function() {
var any = new j$.Any(Object);
var any = new jasmineUnderTest.Any(Object);
expect(any.asymmetricMatch({})).toBe(true);
});
it("matches a Boolean", function() {
var any = new j$.Any(Boolean);
var any = new jasmineUnderTest.Any(Boolean);
expect(any.asymmetricMatch(true)).toBe(true);
});
it("matches another constructed object", function() {
var Thing = function() {},
any = new j$.Any(Thing);
any = new jasmineUnderTest.Any(Thing);
expect(any.asymmetricMatch(new Thing())).toBe(true);
});
it("jasmineToString's itself", function() {
var any = new j$.Any(Number);
var any = new jasmineUnderTest.Any(Number);
expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');
});
@@ -45,7 +45,7 @@ describe("Any", function() {
describe("when called without an argument", function() {
it("tells the user to pass a constructor or use jasmine.anything()", function() {
expect(function() {
new j$.Any();
new jasmineUnderTest.Any();
}).toThrowError(TypeError, /constructor.*anything/);
});
});

View File

@@ -1,43 +1,43 @@
describe("Anything", function() {
it("matches a string", function() {
var anything = new j$.Anything();
var anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch('foo')).toBe(true);
});
it("matches a number", function() {
var anything = new j$.Anything();
var anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch(42)).toBe(true);
});
it("matches an object", function() {
var anything = new j$.Anything();
var anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch({ foo: 'bar' })).toBe(true);
});
it("matches an array", function() {
var anything = new j$.Anything();
var anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch([1,2,3])).toBe(true);
});
it("doesn't match undefined", function() {
var anything = new j$.Anything();
var anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch()).toBe(false);
expect(anything.asymmetricMatch(undefined)).toBe(false);
});
it("doesn't match null", function() {
var anything = new j$.Anything();
var anything = new jasmineUnderTest.Anything();
expect(anything.asymmetricMatch(null)).toBe(false);
});
it("jasmineToString's itself", function() {
var anything = new j$.Anything();
var anything = new jasmineUnderTest.Anything();
expect(anything.jasmineToString()).toEqual("<jasmine.anything>");
});

View File

@@ -1,12 +1,12 @@
describe("ArrayContaining", function() {
it("matches any actual to an empty array", function() {
var containing = new j$.ArrayContaining([]);
var containing = new jasmineUnderTest.ArrayContaining([]);
expect(containing.asymmetricMatch("foo")).toBe(true);
});
it("does not work when not passed an array", function() {
var containing = new j$.ArrayContaining("foo");
var containing = new jasmineUnderTest.ArrayContaining("foo");
expect(function() {
containing.asymmetricMatch([]);
@@ -14,26 +14,39 @@ describe("ArrayContaining", function() {
});
it("matches when the item is in the actual", function() {
var containing = new j$.ArrayContaining(["foo"]);
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
expect(containing.asymmetricMatch(["foo"])).toBe(true);
});
it("matches when additional items are in the actual", function() {
var containing = new j$.ArrayContaining(["foo"]);
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
expect(containing.asymmetricMatch(["foo", "bar"])).toBe(true);
});
it("does not match when the item is not in the actual", function() {
var containing = new j$.ArrayContaining(["foo"]);
var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
expect(containing.asymmetricMatch(["bar"])).toBe(false);
});
it("jasmineToStrings itself", function() {
var containing = new j$.ArrayContaining([]);
var containing = new jasmineUnderTest.ArrayContaining([]);
expect(containing.jasmineToString()).toMatch("<jasmine.arrayContaining");
});
it("uses custom equality testers", function() {
var tester = function(a, b) {
// All "foo*" strings match each other.
if (typeof a == "string" && typeof b == "string" &&
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
return true;
}
};
var containing = new jasmineUnderTest.ArrayContaining(["fooVal"]);
expect(containing.asymmetricMatch(["fooBar"], [tester])).toBe(true);
});
});

View File

@@ -1,13 +1,13 @@
describe("ObjectContaining", function() {
it("matches any actual to an empty object", function() {
var containing = new j$.ObjectContaining({});
var containing = new jasmineUnderTest.ObjectContaining({});
expect(containing.asymmetricMatch("foo")).toBe(true);
});
it("does not match an empty object actual", function() {
var containing = new j$.ObjectContaining("foo");
var containing = new jasmineUnderTest.ObjectContaining("foo");
expect(function() {
containing.asymmetricMatch({})
@@ -15,43 +15,43 @@ describe("ObjectContaining", function() {
});
it("matches when the key/value pair is present in the actual", function() {
var containing = new j$.ObjectContaining({foo: "fooVal"});
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"})).toBe(true);
});
it("does not match when the key/value pair is not present in the actual", function() {
var containing = new j$.ObjectContaining({foo: "fooVal"});
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
expect(containing.asymmetricMatch({bar: "barVal", quux: "quuxVal"})).toBe(false);
});
it("does not match when the key is present but the value is different in the actual", function() {
var containing = new j$.ObjectContaining({foo: "other"});
var containing = new jasmineUnderTest.ObjectContaining({foo: "other"});
expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"})).toBe(false);
});
it("jasmineToString's itself", function() {
var containing = new j$.ObjectContaining({});
var containing = new jasmineUnderTest.ObjectContaining({});
expect(containing.jasmineToString()).toMatch("<jasmine.objectContaining");
});
it("matches recursively", function() {
var containing = new j$.ObjectContaining({one: new j$.ObjectContaining({two: {}})});
var containing = new jasmineUnderTest.ObjectContaining({one: new jasmineUnderTest.ObjectContaining({two: {}})});
expect(containing.asymmetricMatch({one: {two: {}}})).toBe(true);
});
it("matches when key is present with undefined value", function() {
var containing = new j$.ObjectContaining({ one: undefined });
var containing = new jasmineUnderTest.ObjectContaining({ one: undefined });
expect(containing.asymmetricMatch({ one: undefined })).toBe(true);
});
it("does not match when key with undefined value is not present", function() {
var containing = new j$.ObjectContaining({ one: undefined });
var containing = new jasmineUnderTest.ObjectContaining({ one: undefined });
expect(containing.asymmetricMatch({})).toBe(false);
});
@@ -60,7 +60,7 @@ describe("ObjectContaining", function() {
// IE 8 doesn't support `definePropery` on non-DOM nodes
if (jasmine.getEnv().ieVersion < 9) { return; }
var containing = new j$.ObjectContaining({ foo: "fooVal" });
var containing = new jasmineUnderTest.ObjectContaining({ foo: "fooVal" });
var definedPropertyObject = {};
Object.defineProperty(definedPropertyObject, "foo", {
@@ -70,7 +70,7 @@ describe("ObjectContaining", function() {
});
it("matches prototype properties", function(){
var containing = new j$.ObjectContaining({ foo: "fooVal" });
var containing = new jasmineUnderTest.ObjectContaining({ foo: "fooVal" });
var prototypeObject = {foo: "fooVal"};
var obj;
@@ -86,4 +86,17 @@ describe("ObjectContaining", function() {
expect(containing.asymmetricMatch(obj)).toBe(true);
});
it("uses custom equality testers", function() {
var tester = function(a, b) {
// All "foo*" strings match each other.
if (typeof a == "string" && typeof b == "string" &&
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
return true;
}
};
var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
expect(containing.asymmetricMatch({foo: "fooBar"}, [tester])).toBe(true);
});
});

View File

@@ -1,13 +1,13 @@
describe("StringMatching", function() {
it("matches a string against a provided regexp", function() {
var matcher = new j$.StringMatching(/foo/);
var matcher = new jasmineUnderTest.StringMatching(/foo/);
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
});
it("matches a string against provided string", function() {
var matcher = new j$.StringMatching('foo');
var matcher = new jasmineUnderTest.StringMatching('foo');
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
@@ -15,12 +15,12 @@ describe("StringMatching", function() {
it("raises an Error when the expected is not a String or RegExp", function() {
expect(function() {
new j$.StringMatching({});
new jasmineUnderTest.StringMatching({});
}).toThrowError(/not a String or a RegExp/);
});
it("jasmineToString's itself", function() {
var matching = new j$.StringMatching(/^foo/);
var matching = new jasmineUnderTest.StringMatching(/^foo/);
expect(matching.jasmineToString()).toEqual("<jasmine.stringMatching(/^foo/)>");
});

View File

@@ -0,0 +1,13 @@
describe('formatErrorMsg', function () {
it('should format an error with a domain', function() {
var formator = jasmineUnderTest.formatErrorMsg('api');
expect(formator('message')).toBe('api : message');
expect(formator('message2')).toBe('api : message2');
});
it('should format an error with a domain and usage', function() {
var formator = jasmineUnderTest.formatErrorMsg('api', 'with a param');
expect(formator('message')).toBe('api : message\nUsage: with a param');
expect(formator('message2')).toBe('api : message2\nUsage: with a param');
});
});

View File

@@ -3,7 +3,7 @@ describe("Custom Matchers (Integration)", function() {
var fakeTimer;
beforeEach(function() {
env = new j$.Env();
env = new jasmineUnderTest.Env();
});
it("allows adding more matchers local to a spec", function(done) {
@@ -56,6 +56,53 @@ describe("Custom Matchers (Integration)", function() {
env.execute();
});
it("passes the spec if the custom equality matcher passes for types nested inside asymmetric equality testers", function(done) {
env.it("spec using custom equality matcher", function() {
var customEqualityFn = function(a, b) {
// All "foo*" strings match each other.
if (typeof a == "string" && typeof b == "string" &&
a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
return true;
}
};
env.addCustomEqualityTester(customEqualityFn);
env.expect({foo: 'fooValue'}).toEqual(jasmine.objectContaining({foo: 'fooBar'}));
env.expect(['fooValue']).toEqual(jasmine.arrayContaining(['fooBar']));
});
var specExpectations = function(result) {
expect(result.status).toEqual('passed');
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
});
it("displays an appropriate failure message if a custom equality matcher fails", function(done) {
env.it("spec using custom equality matcher", function() {
var customEqualityFn = function(a, b) {
// "foo" is not equal to anything
if (a === 'foo' || b === 'foo') {
return false;
}
};
env.addCustomEqualityTester(customEqualityFn);
env.expect({foo: 'foo'}).toEqual({foo: 'foo'});
});
var specExpectations = function(result) {
expect(result.status).toEqual('failed');
expect(result.failedExpectations[0].message).toEqual(
"Expected $.foo = 'foo' to equal 'foo'."
);
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });
env.execute();
});
it("uses the negative compare function for a negative comparison, if provided", function(done) {
env.it("spec with custom negative comparison matcher", function() {
env.addMatchers({
@@ -142,7 +189,7 @@ describe("Custom Matchers (Integration)", function() {
});
var specExpectations = function() {
expect(argumentSpy).toHaveBeenCalledWith(j$.matchersUtil, [customEqualityFn]);
expect(argumentSpy).toHaveBeenCalledWith(jasmineUnderTest.matchersUtil, [customEqualityFn]);
};
env.addReporter({ specDone: specExpectations, jasmineDone: done });

View File

@@ -41,7 +41,7 @@ describe("Env integration", function() {
});
it("Suites execute as expected (no nesting)", function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
calls = [];
var assertions = function() {
@@ -68,7 +68,7 @@ describe("Env integration", function() {
});
it("Nested Suites execute as expected", function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
calls = [];
var assertions = function() {
@@ -101,7 +101,7 @@ describe("Env integration", function() {
});
it("Multiple top-level Suites execute as expected", function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
calls = [];
var assertions = function() {
@@ -142,7 +142,7 @@ describe("Env integration", function() {
});
it('explicitly fails a spec', function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
specDone = jasmine.createSpy('specDone');
env.addReporter({
@@ -181,6 +181,12 @@ describe("Env integration", function() {
}
})]
}));
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
description: 'pretty prints objects',
failedExpectations: [jasmine.objectContaining({
message: 'Failed: Object({ prop: \'value\', arr: [ \'works\', true ] })'
})]
}));
done();
}
});
@@ -197,6 +203,27 @@ describe("Env integration", function() {
env.it('has a message and stack trace from an Error', function() {
env.fail(new Error('error message'));
});
env.it('pretty prints objects', function() {
env.fail({prop: 'value', arr: ['works', true]});
})
});
env.execute();
});
it("produces an understandable error message when 'fail' is used outside of a current spec", function(done) {
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
reporter.jasmineDone.and.callFake(done);
env.addReporter(reporter);
env.describe("A Suite", function() {
env.it("an async spec that is actually synchronous", function(underTestCallback) {
underTestCallback();
});
expect(function() { env.fail(); }).toThrowError(/'fail' was used when there was no current spec/);
});
env.execute();
@@ -204,7 +231,7 @@ describe("Env integration", function() {
it("calls associated befores/specs/afters with the same 'this'", function(done) {
var env = new j$.Env();
var env = new jasmineUnderTest.Env();
env.addReporter({jasmineDone: done});
env.describe("tests", function() {
@@ -241,7 +268,7 @@ describe("Env integration", function() {
});
it("calls associated befores/its/afters with the same 'this' for an async spec", function(done) {
var env = new j$.Env();
var env = new jasmineUnderTest.Env();
env.addReporter({jasmineDone: done});
@@ -267,7 +294,7 @@ describe("Env integration", function() {
});
it("calls associated beforeAlls/afterAlls only once per suite", function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
before = jasmine.createSpy('beforeAll'),
after = jasmine.createSpy('afterAll');
@@ -299,7 +326,7 @@ describe("Env integration", function() {
});
it("calls associated beforeAlls/afterAlls only once per suite for async", function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
before = jasmine.createSpy('beforeAll'),
after = jasmine.createSpy('afterAll');
@@ -338,7 +365,7 @@ describe("Env integration", function() {
});
it("calls associated beforeAlls/afterAlls with the cascaded 'this'", function(done) {
var env = new j$.Env();
var env = new jasmineUnderTest.Env();
env.addReporter({jasmineDone: done});
@@ -392,7 +419,7 @@ describe("Env integration", function() {
});
it("fails all underlying specs when the beforeAll fails", function (done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
reporter.jasmineDone.and.callFake(function() {
@@ -431,7 +458,7 @@ describe("Env integration", function() {
describe('suiteDone reporting', function(){
it("reports when an afterAll fails an expectation", function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
@@ -458,35 +485,35 @@ describe("Env integration", function() {
});
it("if there are no specs, it still reports correctly", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('outer suite', [
'Expected 1 to equal 2.',
'Expected 2 to equal 3.'
]);
done();
});
env.addReporter(reporter);
env.describe('outer suite', function() {
env.describe('inner suite', function() {
env.it('spec', function(){ });
});
env.afterAll(function() {
env.expect(1).toEqual(2);
env.expect(2).toEqual(3);
});
});
env.execute();
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('outer suite', [
'Expected 1 to equal 2.',
'Expected 2 to equal 3.'
]);
done();
});
env.addReporter(reporter);
env.describe('outer suite', function() {
env.describe('inner suite', function() {
env.it('spec', function(){ });
});
env.afterAll(function() {
env.expect(1).toEqual(2);
env.expect(2).toEqual(3);
});
});
env.execute();
});
it("reports when afterAll throws an exception", function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
error = new Error('After All Exception'),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
@@ -512,7 +539,7 @@ describe("Env integration", function() {
});
it("reports when an async afterAll fails an expectation", function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
@@ -538,7 +565,7 @@ describe("Env integration", function() {
});
it("reports when an async afterAll throws an exception", function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
error = new Error('After All Exception'),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
@@ -565,8 +592,55 @@ describe("Env integration", function() {
});
});
it('cascades expecatation failures in global beforeAll down to children', function(done) {
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj(['specDone', 'jasmineDone']);
reporter.jasmineDone.and.callFake(function(results) {
expect(results.failedExpectations).toEqual([]);
expect(reporter.specDone).toHaveFailedExpecationsForRunnable('is a spec', [
'Expected 1 to be 0.'
]);
done();
});
env.beforeAll(function() {
env.expect(1).toBe(0);
});
env.it('is a spec', function() {
env.expect(true).toBe(true);
});
env.addReporter(reporter);
env.execute();
});
it('reports expectation failures in global afterAll', function(done) {
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj(['jasmineDone']);
reporter.jasmineDone.and.callFake(function(results) {
expect(results.failedExpectations).toEqual([jasmine.objectContaining({ message: 'Expected 1 to be 0.' })]);
done();
});
env.afterAll(function() {
env.expect(1).toBe(0);
});
env.it('is a spec', function() {
env.expect(true).toBe(true);
});
env.addReporter(reporter);
env.execute();
});
it("Allows specifying which specs and suites to run", function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
calls = [],
suiteCallback = jasmine.createSpy('suite callback'),
firstSpec,
@@ -602,7 +676,7 @@ describe("Env integration", function() {
});
it('runs before and after all functions for runnables provided to .execute()', function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
calls = [],
first_spec,
second_spec;
@@ -638,7 +712,7 @@ describe("Env integration", function() {
});
it("Functions can be spied on and have their calls tracked", function (done) {
var env = new j$.Env();
var env = new jasmineUnderTest.Env();
var originalFunctionWasCalled = false;
var subject = {
@@ -677,8 +751,33 @@ describe("Env integration", function() {
env.execute();
});
it('can be configured to allow respying on functions', function () {
var env = new jasmineUnderTest.Env(),
foo = {
bar: function () {
return 1;
}
};
env.allowRespy(true);
env.describe('test suite', function(){
env.it('spec 0', function(){
env.spyOn(foo,'bar');
var error = null;
expect(function() {
env.spyOn(foo, 'bar');
}).not.toThrow();
});
});
env.execute();
});
it('removes all spies added in a spec after the spec is complete', function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
originalFoo = function() {},
testObj = {
foo: originalFoo
@@ -706,7 +805,7 @@ describe("Env integration", function() {
});
it('removes all spies added in a suite after the suite is complete', function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
originalFoo = function() {},
testObj = {
foo: originalFoo
@@ -716,17 +815,17 @@ describe("Env integration", function() {
env.beforeAll(function() { env.spyOn(testObj, 'foo');})
env.it('spec 0', function() {
expect(j$.isSpy(testObj.foo)).toBe(true);
expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(true);
});
env.it('spec 1', function() {
expect(j$.isSpy(testObj.foo)).toBe(true);
expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(true);
});
});
env.describe('another suite', function() {
env.it('spec 2', function() {
expect(j$.isSpy(testObj.foo)).toBe(false);
expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(false);
});
});
@@ -735,11 +834,36 @@ describe("Env integration", function() {
env.execute();
});
it('removes a spy from the top suite after the run is complete', function(done) {
var env = new jasmineUnderTest.Env(),
originalFoo = function() {},
testObj = {
foo: originalFoo
};
env.beforeAll(function() {
env.spyOn(testObj, 'foo');
});
env.it('spec', function() {
expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(true);
});
env.addReporter({
jasmineDone: function() {
expect(jasmineUnderTest.isSpy(testObj.foo)).toBe(false);
done();
}
});
env.execute();
});
it("Mock clock can be installed and used in tests", function(done) {
var globalSetTimeout = jasmine.createSpy('globalSetTimeout'),
delayedFunctionForGlobalClock = jasmine.createSpy('delayedFunctionForGlobalClock'),
delayedFunctionForMockClock = jasmine.createSpy('delayedFunctionForMockClock'),
env = new j$.Env({global: { setTimeout: globalSetTimeout }});
env = new jasmineUnderTest.Env({global: { setTimeout: globalSetTimeout }});
var assertions = function() {
expect(delayedFunctionForMockClock).toHaveBeenCalled();
@@ -769,7 +893,7 @@ describe("Env integration", function() {
});
it("should run async specs in order, waiting for them to complete", function(done) {
var env = new j$.Env(), mutatedVar;
var env = new jasmineUnderTest.Env(), mutatedVar;
env.describe("tests", function() {
env.beforeEach(function() {
@@ -796,17 +920,17 @@ describe("Env integration", function() {
var originalTimeout;
beforeEach(function() {
originalTimeout = j$.DEFAULT_TIMEOUT_INTERVAL;
originalTimeout = jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL;
jasmine.clock().install();
});
afterEach(function() {
jasmine.clock().uninstall();
j$.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});
it("should wait a specified interval before failing specs haven't called done yet", function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
reporter.specDone.and.callFake(function() {
@@ -819,7 +943,7 @@ describe("Env integration", function() {
});
env.addReporter(reporter);
j$.DEFAULT_TIMEOUT_INTERVAL = 8414;
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 8414;
env.it("async spec that doesn't call done", function(underTestCallback) {
env.expect(true).toBeTruthy();
@@ -830,7 +954,7 @@ describe("Env integration", function() {
});
it("should wait a specified interval before failing beforeAll's and their associated specs that haven't called done", function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
reporter.jasmineDone.and.callFake(function() {
@@ -841,10 +965,10 @@ describe("Env integration", function() {
});
env.addReporter(reporter);
j$.DEFAULT_TIMEOUT_INTERVAL = 1290;
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 1290;
env.beforeAll(function(done) {
jasmine.clock().tick(1290);
env.beforeAll(function(innerDone) {
jasmine.clock().tick(1291);
});
env.it("spec that will be failed", function() {
@@ -858,18 +982,19 @@ describe("Env integration", function() {
env.execute();
});
it("should not use the mock clock for asynchronous timeouts", function(){
var env = new j$.Env(),
it("should not use the mock clock for asynchronous timeouts", function(done){
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]),
clock = env.clock;
reporter.jasmineDone.and.callFake(function() {
expect(reporter.specDone.calls.count()).toEqual(1);
expect(reporter.specDone.calls.argsFor(0)[0]).toEqual(jasmine.objectContaining({status: 'passed'}));
done();
});
env.addReporter(reporter);
j$.DEFAULT_TIMEOUT_INTERVAL = 5;
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 5;
env.beforeAll(function() {
clock.install();
@@ -879,17 +1004,18 @@ describe("Env integration", function() {
clock.uninstall();
});
env.it("spec that should not time out", function(done) {
env.it("spec that should not time out", function(innerDone) {
clock.tick(6);
expect(true).toEqual(true);
done();
innerDone();
jasmine.clock().tick(1);
});
env.execute();
});
it("should wait the specified interval before reporting an afterAll that fails to call done", function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
@@ -900,7 +1026,7 @@ describe("Env integration", function() {
});
env.addReporter(reporter);
j$.DEFAULT_TIMEOUT_INTERVAL = 3000;
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 3000;
env.describe('my suite', function() {
env.it('my spec', function() {
@@ -909,14 +1035,16 @@ describe("Env integration", function() {
env.afterAll(function(innerDone) {
jasmine.clock().tick(3001);
innerDone();
jasmine.clock().tick(1);
});
});
env.execute();
jasmine.clock().tick(1);
});
it('should wait a custom interval before reporting async functions that fail to call done', function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function() {
@@ -944,7 +1072,7 @@ describe("Env integration", function() {
});
env.addReporter(reporter);
j$.DEFAULT_TIMEOUT_INTERVAL = 10000;
jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL = 10000;
env.describe('suite', function() {
env.describe('beforeAll', function() {
@@ -993,7 +1121,7 @@ describe("Env integration", function() {
});
it('explicitly fails an async spec', function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
specDone = jasmine.createSpy('specDone');
env.addReporter({
@@ -1033,6 +1161,8 @@ describe("Env integration", function() {
env.fail();
innerDone();
}, 1);
jasmine.clock().tick(1);
jasmine.clock().tick(1);
});
env.it('specifies a message', function(innerDone) {
@@ -1040,12 +1170,16 @@ describe("Env integration", function() {
env.fail('messy message');
innerDone();
}, 1);
jasmine.clock().tick(1);
jasmine.clock().tick(1);
});
env.it('fails via the done callback', function(innerDone) {
setTimeout(function() {
innerDone.fail('done failed');
}, 1);
jasmine.clock().tick(1);
jasmine.clock().tick(1);
});
env.it('has a message from an Error', function(innerDone) {
@@ -1053,20 +1187,18 @@ describe("Env integration", function() {
env.fail(new Error('error message'));
innerDone();
}, 1);
jasmine.clock().tick(1);
jasmine.clock().tick(1);
});
});
env.execute();
jasmine.clock().tick(1);
jasmine.clock().tick(1);
jasmine.clock().tick(1);
jasmine.clock().tick(1);
});
});
describe('focused tests', function() {
it('should only run the focused tests', function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
calls = [];
var assertions = function() {
@@ -1089,8 +1221,8 @@ describe("Env integration", function() {
env.execute();
});
it('should only run focused suites', function(){
var env = new j$.Env(),
it('should only run focused suites', function(done){
var env = new jasmineUnderTest.Env(),
calls = [];
var assertions = function() {
@@ -1116,7 +1248,7 @@ describe("Env integration", function() {
});
it('should run focused tests inside an xdescribe', function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted",
"jasmineDone",
@@ -1151,7 +1283,7 @@ describe("Env integration", function() {
});
it('should run focused suites inside an xdescribe', function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted",
"jasmineDone",
@@ -1189,7 +1321,7 @@ describe("Env integration", function() {
});
it("should report as expected", function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted",
"jasmineDone",
@@ -1259,7 +1391,7 @@ describe("Env integration", function() {
});
it('should report pending spec messages', function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [
'specDone',
'jasmineDone'
@@ -1282,8 +1414,30 @@ describe("Env integration", function() {
env.execute();
});
it('should report using fallback reporter', function(done) {
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [
'specDone',
'jasmineDone'
]);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.specDone).toHaveBeenCalled();
done();
});
env.provideFallbackReporter(reporter);
env.it('will be pending', function() {
env.pending('with a message');
});
env.execute();
});
it('should report xdescribes as expected', function(done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineStarted",
"jasmineDone",
@@ -1298,10 +1452,10 @@ describe("Env integration", function() {
totalSpecsDefined: 1
});
expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({ status: 'pending' }));
expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({ status: 'disabled' }));
expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({ description: 'xd out', status: 'pending' }));
expect(reporter.suiteDone.calls.count()).toBe(4);
done();
});
@@ -1323,7 +1477,7 @@ describe("Env integration", function() {
});
it("should be possible to get full name from a spec", function() {
var env = new j$.Env({global: { setTimeout: setTimeout }}),
var env = new jasmineUnderTest.Env({global: { setTimeout: setTimeout }}),
topLevelSpec, nestedSpec, doublyNestedSpec;
env.describe("my tests", function() {
@@ -1345,7 +1499,7 @@ describe("Env integration", function() {
});
it("Custom equality testers should be per spec", function(done) {
var env = new j$.Env({global: { setTimeout: setTimeout }}),
var env = new jasmineUnderTest.Env({global: { setTimeout: setTimeout }}),
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineDone",
"specDone"
@@ -1378,7 +1532,7 @@ describe("Env integration", function() {
});
it("Custom equality testers should be per suite", function(done) {
var env = new j$.Env({global: { setTimeout: setTimeout }}),
var env = new jasmineUnderTest.Env({global: { setTimeout: setTimeout }}),
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineDone",
"specDone"
@@ -1420,7 +1574,7 @@ describe("Env integration", function() {
});
it("Custom equality testers for toContain should be per spec", function(done) {
var env = new j$.Env({global: { setTimeout: setTimeout }}),
var env = new jasmineUnderTest.Env({global: { setTimeout: setTimeout }}),
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineDone",
"specDone"
@@ -1453,21 +1607,24 @@ describe("Env integration", function() {
});
it("produces an understandable error message when an 'expect' is used outside of a current spec", function(done) {
var env = new j$.Env();
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReporter', ['jasmineDone']);
reporter.jasmineDone.and.callFake(done);
env.addReporter(reporter);
env.describe("A Suite", function() {
env.it("an async spec that is actually synchronous", function(underTestCallback) {
underTestCallback();
expect(function() { env.expect('a').toEqual('a'); }).toThrowError(/'expect' was used when there was no current spec/);
done();
});
expect(function() { env.expect('a').toEqual('a'); }).toThrowError(/'expect' was used when there was no current spec/);
});
env.execute();
});
it("Custom equality testers for toContain should be per suite", function(done) {
var env = new j$.Env({global: { setTimeout: setTimeout }}),
var env = new jasmineUnderTest.Env({global: { setTimeout: setTimeout }}),
reporter = jasmine.createSpyObj('fakeReporter', [
"jasmineDone",
"specDone"
@@ -1509,7 +1666,7 @@ describe("Env integration", function() {
});
it("Custom matchers should be per spec", function(done) {
var env = new j$.Env({global: { setTimeout: setTimeout }}),
var env = new jasmineUnderTest.Env({global: { setTimeout: setTimeout }}),
matchers = {
toFoo: function() {}
};
@@ -1531,7 +1688,7 @@ describe("Env integration", function() {
});
it("Custom matchers should be per suite", function(done) {
var env = new j$.Env({global: { setTimeout: setTimeout }}),
var env = new jasmineUnderTest.Env({global: { setTimeout: setTimeout }}),
matchers = {
toFoo: function() {}
};
@@ -1560,7 +1717,7 @@ describe("Env integration", function() {
});
it('throws an exception if you try to create a spy outside of a runnable', function (done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
obj = {fn: function () {}},
exception;
@@ -1583,7 +1740,7 @@ describe("Env integration", function() {
});
it('throws an exception if you try to add a matcher outside of a runnable', function (done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
obj = {fn: function () {}},
exception;
@@ -1606,7 +1763,7 @@ describe("Env integration", function() {
});
it('throws an exception if you try to add a custom equality outside of a runnable', function (done) {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
obj = {fn: function () {}},
exception;
@@ -1627,4 +1784,37 @@ describe("Env integration", function() {
env.execute();
});
it("should associate errors thrown from async code with the correct runnable", function(done) {
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone','specDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpecationsForRunnable('async suite', [
/^(((Uncaught )?Error: suite( thrown)?)|(suite thrown))$/
]);
expect(reporter.specDone).toHaveFailedExpecationsForRunnable('suite async spec', [
/^(((Uncaught )?Error: spec( thrown)?)|(spec thrown))$/
]);
done();
});
env.addReporter(reporter);
env.describe('async suite', function() {
env.afterAll(function(innerDone) {
setTimeout(function() { throw new Error('suite'); }, 1);
}, 10);
env.it('spec', function() {});
});
env.describe('suite', function() {
env.it('async spec', function(innerDone) {
setTimeout(function() { throw new Error('spec'); }, 1);
}, 10);
});
env.execute();
});
});

View File

@@ -2,7 +2,7 @@ describe("jasmine spec running", function () {
var env;
beforeEach(function() {
env = new j$.Env();
env = new jasmineUnderTest.Env();
});
it('should assign spec ids sequentially', function() {
@@ -169,9 +169,25 @@ describe("jasmine spec running", function () {
env.execute();
});
it("should run multiple befores and afters in the order they are declared", function(done) {
it("should run multiple befores and afters ordered so functions declared later are treated as more specific", function(done) {
var actions = [];
env.beforeAll(function() {
actions.push('runner beforeAll1');
});
env.afterAll(function() {
actions.push('runner afterAll1');
});
env.beforeAll(function() {
actions.push('runner beforeAll2');
});
env.afterAll(function() {
actions.push('runner afterAll2');
});
env.beforeEach(function () {
actions.push('runner beforeEach1');
});
@@ -212,15 +228,19 @@ describe("jasmine spec running", function () {
var assertions = function() {
var expected = [
"runner beforeAll1",
"runner beforeAll2",
"runner beforeEach1",
"runner beforeEach2",
"beforeEach1",
"beforeEach2",
"outer it 1",
"afterEach1",
"afterEach2",
"afterEach1",
"runner afterEach2",
"runner afterEach1",
"runner afterEach2"
"runner afterAll2",
"runner afterAll1"
];
expect(actions).toEqual(expected);
done();
@@ -475,7 +495,7 @@ describe("jasmine spec running", function () {
env.execute();
});
it('focused runnables unfocus ancestor focused suites', function() {
it('focused runnables unfocus ancestor focused suites', function(done) {
var actions = [];
env.fdescribe('focused suite', function() {
@@ -518,7 +538,29 @@ describe("jasmine spec running", function () {
env.execute();
});
it("should allow top level suites to be disabled", function() {
it("shouldn't run before/after functions in disabled suites", function(done) {
var shouldNotRun = jasmine.createSpy("shouldNotRun"),
suite = env.xdescribe('A disabled Suite', function() {
// None of the before/after functions should run.
env.beforeAll(shouldNotRun);
env.beforeEach(shouldNotRun);
env.afterEach(shouldNotRun);
env.afterAll(shouldNotRun);
env.it('spec inside a disabled suite', shouldNotRun);
});
var assertions = function() {
expect(shouldNotRun).not.toHaveBeenCalled();
done();
};
env.addReporter({jasmineDone: assertions});
env.execute();
});
it("should allow top level suites to be disabled", function(done) {
var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),
otherSpec = jasmine.createSpy("otherSpec");
@@ -556,15 +598,24 @@ describe("jasmine spec running", function () {
env.execute();
});
// TODO: is this useful? It doesn't catch syntax errors
xit("should recover gracefully when there are errors in describe functions", function() {
var specs = [];
var superSimpleReporter = new j$.Reporter();
superSimpleReporter.reportSpecResults = function(result) {
specs.push("Spec: " + result.fullName);
};
it("should recover gracefully when there are errors in describe functions", function(done) {
var specs = [],
reporter = jasmine.createSpyObj(['specDone', 'jasmineDone']);
try {
reporter.specDone.and.callFake(function(result) {
specs.push(result.fullName);
});
reporter.jasmineDone.and.callFake(function() {
expect(specs).toContain('outer1 inner1 should thingy');
expect(specs).toContain('outer1 inner1 encountered a declaration exception');
expect(specs).toContain('outer1 inner2 should other thingy');
expect(specs).toContain('outer1 encountered a declaration exception');
expect(specs).toContain('outer2 should xxx');
done();
});
expect(function() {
env.describe("outer1", function() {
env.describe("inner1", function() {
env.it("should thingy", function() {
@@ -583,8 +634,7 @@ describe("jasmine spec running", function () {
throw new Error("fake error");
});
} catch(e) {
}
}).not.toThrow();
env.describe("outer2", function() {
env.it("should xxx", function() {
@@ -592,17 +642,8 @@ describe("jasmine spec running", function () {
});
});
env.addReporter(superSimpleReporter);
env.addReporter(reporter);
env.execute();
expect(specs.join('')).toMatch(new RegExp(
'Spec: outer1 inner1 should thingy.' +
'Spec: outer1 inner1 encountered a declaration exception.' +
'Spec: outer1 inner2 should other thingy.' +
'Spec: outer1 encountered a declaration exception.' +
'Spec: outer2 should xxx.'
));
});
it("re-enters suites that have no *Alls", function(done) {

View File

@@ -0,0 +1,47 @@
describe("DiffBuilder", function() {
it("records the actual and expected objects", function() {
var diffBuilder = jasmineUnderTest.DiffBuilder();
diffBuilder.record({x: 'actual'}, {x: 'expected'});
expect(diffBuilder.getMessage()).toEqual("Expected Object({ x: 'actual' }) to equal Object({ x: 'expected' }).");
});
it("prints the path at which the difference was found", function() {
var diffBuilder = jasmineUnderTest.DiffBuilder();
diffBuilder.withPath('foo', function() {
diffBuilder.record({x: 'actual'}, {x: 'expected'});
});
expect(diffBuilder.getMessage()).toEqual("Expected $.foo = Object({ x: 'actual' }) to equal Object({ x: 'expected' }).");
});
it("prints multiple messages, separated by newlines", function() {
var diffBuilder = jasmineUnderTest.DiffBuilder();
diffBuilder.withPath('foo', function() {
diffBuilder.record(1, 2);
});
var message =
"Expected $.foo = 1 to equal 2.\n" +
"Expected 3 to equal 4.";
diffBuilder.record(3, 4);
expect(diffBuilder.getMessage()).toEqual(message);
});
it("allows customization of the message", function() {
var diffBuilder = jasmineUnderTest.DiffBuilder();
function darthVaderFormatter(actual, expected, path) {
return "I find your lack of " + expected + " disturbing. (was " + actual + ", at " + path + ")"
}
diffBuilder.withPath('x', function() {
diffBuilder.record('bar', 'foo', darthVaderFormatter);
});
expect(diffBuilder.getMessage()).toEqual("I find your lack of foo disturbing. (was bar, at $.x)");
});
});

View File

@@ -0,0 +1,13 @@
describe('NullDiffBuilder', function() {
it('responds to withPath() by calling the passed function', function() {
var spy = jasmine.createSpy('callback');
jasmineUnderTest.NullDiffBuilder().withPath('does not matter', spy);
expect(spy).toHaveBeenCalled();
});
it('responds to record()', function() {
expect(function() {
jasmineUnderTest.NullDiffBuilder().record('does not matter');
}).not.toThrow();
})
});

View File

@@ -0,0 +1,43 @@
describe('ObjectPath', function() {
var ObjectPath = jasmineUnderTest.ObjectPath;
it('represents the path to a node in an object tree', function() {
expect(new ObjectPath(['foo', 'bar']).toString()).toEqual('$.foo.bar');
});
it('has a depth', function() {
expect(new ObjectPath().depth()).toEqual(0);
expect(new ObjectPath(['foo']).depth()).toEqual(1);
});
it('renders numbers as array access', function() {
expect(new ObjectPath(['foo', 0]).toString()).toEqual('$.foo[0]');
});
it('renders properties that are valid identifiers with dot notation', function() {
expect(new ObjectPath(['foo123']).toString()).toEqual('$.foo123');
expect(new ObjectPath(['x_y']).toString()).toEqual('$.x_y');
expect(new ObjectPath(['A$B']).toString()).toEqual('$.A$B');
});
it('renders properties with non-identifier-safe characters with square bracket notation', function() {
expect(new ObjectPath(['a b c']).toString()).toEqual("$['a b c']");
expect(new ObjectPath(['1hello']).toString()).toEqual("$['1hello']");
});
it('renders as the empty string when empty', function() {
expect(new ObjectPath().toString()).toEqual('');
});
it('stringifies properties that are not strings or numbers', function() {
expect(new ObjectPath([{}]).toString()).toEqual("$['[object Object]']");
});
it('can be created based on another path', function() {
var root = new ObjectPath();
var path = root.add('foo');
expect(path.toString()).toEqual('$.foo');
expect(root.toString()).toEqual('');
})
});

View File

@@ -1,61 +1,72 @@
describe("matchersUtil", function() {
describe("equals", function() {
it("passes for literals that are triple-equal", function() {
expect(j$.matchersUtil.equals(null, null)).toBe(true);
expect(j$.matchersUtil.equals(void 0, void 0)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(null, null)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(void 0, void 0)).toBe(true);
});
it("fails for things that are not equivalent", function() {
expect(j$.matchersUtil.equals({a: "foo"}, 1)).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals({a: "foo"}, 1)).toBe(false);
});
it("passes for Strings that are equivalent", function() {
expect(j$.matchersUtil.equals("foo", "foo")).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals("foo", "foo")).toBe(true);
});
it("fails for Strings that are not equivalent", function() {
expect(j$.matchersUtil.equals("foo", "bar")).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals("foo", "bar")).toBe(false);
});
it("passes for Numbers that are equivalent", function() {
expect(j$.matchersUtil.equals(123, 123)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(123, 123)).toBe(true);
});
it("fails for Numbers that are not equivalent", function() {
expect(j$.matchersUtil.equals(123, 456)).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(123, 456)).toBe(false);
});
it("passes for Dates that are equivalent", function() {
expect(j$.matchersUtil.equals(new Date("Jan 1, 1970"), new Date("Jan 1, 1970"))).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(new Date("Jan 1, 1970"), new Date("Jan 1, 1970"))).toBe(true);
});
it("fails for Dates that are not equivalent", function() {
expect(j$.matchersUtil.equals(new Date("Jan 1, 1970"), new Date("Feb 3, 1991"))).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(new Date("Jan 1, 1970"), new Date("Feb 3, 1991"))).toBe(false);
});
it("passes for Booleans that are equivalent", function() {
expect(j$.matchersUtil.equals(true, true)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(true, true)).toBe(true);
});
it("fails for Booleans that are not equivalent", function() {
expect(j$.matchersUtil.equals(true, false)).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(true, false)).toBe(false);
});
it("passes for RegExps that are equivalent", function() {
expect(j$.matchersUtil.equals(/foo/, /foo/)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(/foo/, /foo/)).toBe(true);
});
it("fails for RegExps that are not equivalent", function() {
expect(j$.matchersUtil.equals(/foo/, /bar/)).toBe(false);
expect(j$.matchersUtil.equals(new RegExp("foo", "i"), new RegExp("foo"))).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(/foo/, /bar/)).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(new RegExp("foo", "i"), new RegExp("foo"))).toBe(false);
});
it("passes for Arrays that are equivalent", function() {
expect(j$.matchersUtil.equals([1, 2], [1, 2])).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals([1, 2], [1, 2])).toBe(true);
});
it("fails for Arrays that are not equivalent", function() {
expect(j$.matchersUtil.equals([1, 2], [1, 2, 3])).toBe(false);
it("passes for Arrays that are equivalent, with elements added by changing length", function() {
var foo = [];
foo.length = 1;
expect(jasmineUnderTest.matchersUtil.equals(foo, [undefined])).toBe(true);
});
it("fails for Arrays that have different lengths", function() {
expect(jasmineUnderTest.matchersUtil.equals([1, 2], [1, 2, 3])).toBe(false);
});
it("fails for Arrays that have different elements", function() {
expect(jasmineUnderTest.matchersUtil.equals([1, 2, 3], [1, 5, 3])).toBe(false);
});
it("fails for Arrays whose contents are equivalent, but have differing properties", function() {
@@ -65,31 +76,48 @@ describe("matchersUtil", function() {
one.foo = 'bar';
two.foo = 'baz';
expect(j$.matchersUtil.equals(one, two)).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(one, two)).toBe(false);
});
it("passes for Arrays with equivalent contents and properties", function() {
var one = [1,2,3],
two = [1,2,3];
one.foo = 'bar';
two.foo = 'bar';
expect(jasmineUnderTest.matchersUtil.equals(one, two)).toBe(true);
});
it("passes for Errors that are the same type and have the same message", function() {
expect(j$.matchersUtil.equals(new Error("foo"), new Error("foo"))).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(new Error("foo"), new Error("foo"))).toBe(true);
});
it("fails for Errors that are the same type and have different messages", function() {
expect(j$.matchersUtil.equals(new Error("foo"), new Error("bar"))).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(new Error("foo"), new Error("bar"))).toBe(false);
});
it("fails for objects with different constructors", function() {
function One() {}
function Two() {}
expect(jasmineUnderTest.matchersUtil.equals(new One(), new Two())).toBe(false);
});
it("passes for Objects that are equivalent (simple case)", function() {
expect(j$.matchersUtil.equals({a: "foo"}, {a: "foo"})).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals({a: "foo"}, {a: "foo"})).toBe(true);
});
it("fails for Objects that are not equivalent (simple case)", function() {
expect(j$.matchersUtil.equals({a: "foo"}, {a: "bar"})).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals({a: "foo"}, {a: "bar"})).toBe(false);
});
it("passes for Objects that are equivalent (deep case)", function() {
expect(j$.matchersUtil.equals({a: "foo", b: { c: "bar"}}, {a: "foo", b: { c: "bar"}})).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals({a: "foo", b: { c: "bar"}}, {a: "foo", b: { c: "bar"}})).toBe(true);
});
it("fails for Objects that are not equivalent (deep case)", function() {
expect(j$.matchersUtil.equals({a: "foo", b: { c: "baz"}}, {a: "foo", b: { c: "bar"}})).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals({a: "foo", b: { c: "baz"}}, {a: "foo", b: { c: "bar"}})).toBe(false);
});
it("passes for Objects that are equivalent (with cycles)", function() {
@@ -99,7 +127,7 @@ describe("matchersUtil", function() {
actual.b = actual;
expected.b = actual;
expect(j$.matchersUtil.equals(actual, expected)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(actual, expected)).toBe(true);
});
it("fails for Objects that are not equivalent (with cycles)", function() {
@@ -109,15 +137,22 @@ describe("matchersUtil", function() {
actual.b = actual;
expected.b = actual;
expect(j$.matchersUtil.equals(actual, expected)).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(actual, expected)).toBe(false);
});
it("fails for Objects that have the same number of keys, but different keys/values", function () {
var expected = { a: undefined },
actual = { b: 1 };
expect(jasmineUnderTest.matchersUtil.equals(actual, expected)).toBe(false);
})
it("fails when comparing an empty object to an empty array (issue #114)", function() {
var emptyObject = {},
emptyArray = [];
expect(j$.matchersUtil.equals(emptyObject, emptyArray)).toBe(false);
expect(j$.matchersUtil.equals(emptyArray, emptyObject)).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(emptyObject, emptyArray)).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(emptyArray, emptyObject)).toBe(false);
});
it("passes for equivalent frozen objects (GitHub issue #266)", function() {
@@ -129,89 +164,115 @@ describe("matchersUtil", function() {
Object.freeze(a);
Object.freeze(b);
expect(j$.matchersUtil.equals(a,b)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
});
it("passes for equivalent DOM nodes", function() {
if (typeof document === 'undefined') {
return;
describe("when running in a browser", function() {
function isNotRunningInBrowser() {
return typeof document === 'undefined'
}
var a = document.createElement("div");
a.setAttribute("test-attr", "attr-value")
a.appendChild(document.createTextNode('test'));
var b = document.createElement("div");
b.setAttribute("test-attr", "attr-value")
b.appendChild(document.createTextNode('test'));
it("passes for equivalent DOM nodes", function() {
if (isNotRunningInBrowser()) {
return;
}
var a = document.createElement("div");
a.setAttribute("test-attr", "attr-value");
a.appendChild(document.createTextNode('test'));
expect(j$.matchersUtil.equals(a,b)).toBe(true);
var b = document.createElement("div");
b.setAttribute("test-attr", "attr-value");
b.appendChild(document.createTextNode('test'));
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
});
it("passes for equivalent objects from different frames", function() {
if (isNotRunningInBrowser()) {
return;
}
// iframe.contentWindow.eval isn't supported in ie8
if (jasmine.getEnv().ieVersion < 9) {
return;
}
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.contentWindow.eval('window.testObject = {}');
expect(jasmineUnderTest.matchersUtil.equals({}, iframe.contentWindow.testObject)).toBe(true);
document.body.removeChild(iframe);
});
it("fails for DOM nodes with different attributes or child nodes", function() {
if (isNotRunningInBrowser()) {
return;
}
var a = document.createElement("div");
a.setAttribute("test-attr", "attr-value")
a.appendChild(document.createTextNode('test'));
var b = document.createElement("div");
b.setAttribute("test-attr", "attr-value2")
b.appendChild(document.createTextNode('test'));
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(false);
b.setAttribute("test-attr", "attr-value");
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
b.appendChild(document.createTextNode('2'));
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(false);
a.appendChild(document.createTextNode('2'));
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
});
});
it("fails for DOM nodes with different attributes or child nodes", function() {
if (typeof document === 'undefined') {
return;
}
var a = document.createElement("div");
a.setAttribute("test-attr", "attr-value")
a.appendChild(document.createTextNode('test'));
var b = document.createElement("div");
b.setAttribute("test-attr", "attr-value2")
b.appendChild(document.createTextNode('test'));
expect(j$.matchersUtil.equals(a,b)).toBe(false);
b.setAttribute("test-attr", "attr-value");
expect(j$.matchersUtil.equals(a,b)).toBe(true);
b.appendChild(document.createTextNode('2'));
expect(j$.matchersUtil.equals(a,b)).toBe(false);
a.appendChild(document.createTextNode('2'));
expect(j$.matchersUtil.equals(a,b)).toBe(true);
});
it("passes for equivalent objects from different vm contexts", function() {
if (typeof require !== 'function') {
return;
}
var vm = require('vm');
var sandbox = {
obj: null
};
vm.runInNewContext('obj = {a: 1, b: 2}', sandbox);
expect(j$.matchersUtil.equals(sandbox.obj, {a: 1, b: 2})).toBe(true);
});
it("passes for equivalent arrays from different vm contexts", function() {
if (typeof require !== 'function') {
return;
describe("when running in Node", function() {
function isNotRunningInNode() {
return typeof require !== 'function'
}
var vm = require('vm');
var sandbox = {
arr: null
};
vm.runInNewContext('arr = [1, 2]', sandbox);
it("passes for equivalent objects from different vm contexts", function() {
if (isNotRunningInNode()) {
return;
}
var vm = require('vm');
var sandbox = {
obj: null
};
vm.runInNewContext('obj = {a: 1, b: 2}', sandbox);
expect(j$.matchersUtil.equals(sandbox.arr, [1, 2])).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(sandbox.obj, {a: 1, b: 2})).toBe(true);
});
it("passes for equivalent arrays from different vm contexts", function() {
if (isNotRunningInNode()) {
return;
}
var vm = require('vm');
var sandbox = {
arr: null
};
vm.runInNewContext('arr = [1, 2]', sandbox);
expect(jasmineUnderTest.matchersUtil.equals(sandbox.arr, [1, 2])).toBe(true);
});
});
it("passes when Any is used", function() {
var number = 3,
anyNumber = new j$.Any(Number);
anyNumber = new jasmineUnderTest.Any(Number);
expect(j$.matchersUtil.equals(number, anyNumber)).toBe(true);
expect(j$.matchersUtil.equals(anyNumber, number)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(number, anyNumber)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(anyNumber, number)).toBe(true);
});
it("fails when Any is compared to something unexpected", function() {
var number = 3,
anyString = new j$.Any(String);
anyString = new jasmineUnderTest.Any(String);
expect(j$.matchersUtil.equals(number, anyString)).toBe(false);
expect(j$.matchersUtil.equals(anyString, number)).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(number, anyString)).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(anyString, number)).toBe(false);
});
it("passes when ObjectContaining is used", function() {
@@ -219,69 +280,79 @@ describe("matchersUtil", function() {
foo: 3,
bar: 7
},
containing = new j$.ObjectContaining({foo: 3});
containing = new jasmineUnderTest.ObjectContaining({foo: 3});
expect(j$.matchersUtil.equals(obj, containing)).toBe(true);
expect(j$.matchersUtil.equals(containing, obj)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(obj, containing)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(containing, obj)).toBe(true);
});
it("passes when an asymmetric equality tester returns true", function() {
var tester = { asymmetricMatch: function(other) { return true; } };
expect(j$.matchersUtil.equals(false, tester)).toBe(true);
expect(j$.matchersUtil.equals(tester, false)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(false, tester)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(tester, false)).toBe(true);
});
it("fails when an asymmetric equality tester returns false", function() {
var tester = { asymmetricMatch: function(other) { return false; } };
expect(j$.matchersUtil.equals(true, tester)).toBe(false);
expect(j$.matchersUtil.equals(tester, true)).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(true, tester)).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(tester, true)).toBe(false);
});
it("passes when ArrayContaining is used", function() {
var arr = ["foo", "bar"];
expect(j$.matchersUtil.equals(arr, new j$.ArrayContaining(["bar"]))).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(arr, new jasmineUnderTest.ArrayContaining(["bar"]))).toBe(true);
});
it("passes when a custom equality matcher returns true", function() {
var tester = function(a, b) { return true; };
expect(j$.matchersUtil.equals(1, 2, [tester])).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(1, 2, [tester])).toBe(true);
});
it("passes for two empty Objects", function () {
expect(j$.matchersUtil.equals({}, {})).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals({}, {})).toBe(true);
});
describe("when a custom equality matcher is installed that returns 'undefined'", function () {
var tester = function(a, b) { return jasmine.undefined; };
it("passes for two empty Objects", function () {
expect(j$.matchersUtil.equals({}, {}, [tester])).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals({}, {}, [tester])).toBe(true);
});
});
it("fails for equivalents when a custom equality matcher returns false", function() {
var tester = function(a, b) { return false; };
expect(j$.matchersUtil.equals(1, 1, [tester])).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(1, 1, [tester])).toBe(false);
});
it("passes for an asymmetric equality tester that returns true when a custom equality tester return false", function() {
var asymmetricTester = { asymmetricMatch: function(other) { return true; } },
symmetricTester = function(a, b) { return false; };
expect(j$.matchersUtil.equals(asymmetricTester, true, [symmetricTester])).toBe(true);
expect(j$.matchersUtil.equals(true, asymmetricTester, [symmetricTester])).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(asymmetricTester, true, [symmetricTester])).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(true, asymmetricTester, [symmetricTester])).toBe(true);
});
it("passes custom equality matchers to asymmetric equality testers", function() {
var tester = function(a, b) {};
var asymmetricTester = { asymmetricMatch: jasmine.createSpy('asymmetricMatch') };
asymmetricTester.asymmetricMatch.and.returnValue(true);
var other = {};
expect(jasmineUnderTest.matchersUtil.equals(asymmetricTester, other, [tester])).toBe(true);
expect(asymmetricTester.asymmetricMatch).toHaveBeenCalledWith(other, [tester]);
});
it("passes when an Any is compared to an Any that checks for the same type", function() {
var any1 = new j$.Any(Function),
any2 = new j$.Any(Function);
var any1 = new jasmineUnderTest.Any(Function),
any2 = new jasmineUnderTest.Any(Function);
expect(j$.matchersUtil.equals(any1, any2)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(any1, any2)).toBe(true);
});
it("passes for null prototype objects with same properties", function () {
@@ -293,7 +364,7 @@ describe("matchersUtil", function() {
objA.name = 'test';
objB.name = 'test';
expect(j$.matchersUtil.equals(objA, objB)).toBe(true);
expect(jasmineUnderTest.matchersUtil.equals(objA, objB)).toBe(true);
});
it("fails for null prototype objects with different properties", function () {
@@ -305,44 +376,126 @@ describe("matchersUtil", function() {
objA.name = 'test';
objB.test = 'name';
expect(j$.matchersUtil.equals(objA, objB)).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(objA, objB)).toBe(false);
});
it("passes when comparing two empty sets", function() {
jasmine.getEnv().requireFunctioningSets();
expect(jasmineUnderTest.matchersUtil.equals(new Set(), new Set())).toBe(true);
});
it("passes when comparing identical sets", function() {
jasmine.getEnv().requireFunctioningSets();
var setA = new Set([6, 5]);
var setB = new Set();
setB.add(6);
setB.add(5);
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
});
it("fails for sets with different elements", function() {
jasmine.getEnv().requireFunctioningSets();
var setA = new Set([6, 3, 5]);
var setB = new Set([6, 4, 5]);
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
});
it("fails for sets of different size", function() {
jasmine.getEnv().requireFunctioningSets();
var setA = new Set([6, 3]);
var setB = new Set([6, 4, 5]);
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
});
it("fails for sets with different insertion order", function() {
jasmine.getEnv().requireFunctioningSets();
var setA = new Set([3, 6]);
var setB = new Set([6, 3]);
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
});
describe("when running in an environment with array polyfills", function() {
// IE 8 doesn't support `definePropery` on non-DOM nodes
if (jasmine.getEnv().ieVersion < 9) { return; }
var findIndexDescriptor = Object.getOwnPropertyDescriptor(Array.prototype, 'findIndex');
if (!findIndexDescriptor) {
return;
}
beforeEach(function() {
Object.defineProperty(Array.prototype, 'findIndex', {
enumerable: true,
value: function (predicate) {
if (this === null) {
throw new TypeError('Array.prototype.findIndex called on null or undefined');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
var list = Object(this);
var length = list.length >>> 0;
var thisArg = arguments[1];
var value;
for (var i = 0; i < length; i++) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return i;
}
}
return -1;
}
});
});
afterEach(function() {
Object.defineProperty(Array.prototype, 'findIndex', findIndexDescriptor);
});
it("passes when there's an array polyfill", function() {
expect(['foo']).toEqual(['foo']);
});
});
});
describe("contains", function() {
it("passes when expected is a substring of actual", function() {
expect(j$.matchersUtil.contains("ABC", "BC")).toBe(true);
expect(jasmineUnderTest.matchersUtil.contains("ABC", "BC")).toBe(true);
});
it("fails when expected is a not substring of actual", function() {
expect(j$.matchersUtil.contains("ABC", "X")).toBe(false);
expect(jasmineUnderTest.matchersUtil.contains("ABC", "X")).toBe(false);
});
it("passes when expected is an element in an actual array", function() {
expect(j$.matchersUtil.contains(['foo', 'bar'], 'foo')).toBe(true);
expect(jasmineUnderTest.matchersUtil.contains(['foo', 'bar'], 'foo')).toBe(true);
});
it("fails when expected is not an element in an actual array", function() {
expect(j$.matchersUtil.contains(['foo', 'bar'], 'baz')).toBe(false);
expect(jasmineUnderTest.matchersUtil.contains(['foo', 'bar'], 'baz')).toBe(false);
});
it("passes with mixed-element arrays", function() {
expect(j$.matchersUtil.contains(["foo", {some: "bar"}], "foo")).toBe(true);
expect(j$.matchersUtil.contains(["foo", {some: "bar"}], {some: "bar"})).toBe(true);
expect(jasmineUnderTest.matchersUtil.contains(["foo", {some: "bar"}], "foo")).toBe(true);
expect(jasmineUnderTest.matchersUtil.contains(["foo", {some: "bar"}], {some: "bar"})).toBe(true);
});
it("uses custom equality testers if passed in and actual is an Array", function() {
var customTester = function(a, b) {return true;};
expect(j$.matchersUtil.contains([1, 2], 2, [customTester])).toBe(true);
expect(jasmineUnderTest.matchersUtil.contains([1, 2], 2, [customTester])).toBe(true);
});
it("fails when actual is undefined", function() {
expect(j$.matchersUtil.contains(undefined, 'A')).toBe(false);
expect(jasmineUnderTest.matchersUtil.contains(undefined, 'A')).toBe(false);
});
it("fails when actual is null", function() {
expect(j$.matchersUtil.contains(null, 'A')).toBe(false);
expect(jasmineUnderTest.matchersUtil.contains(null, 'A')).toBe(false);
});
it("passes with array-like objects", function() {
@@ -351,7 +504,7 @@ describe("matchersUtil", function() {
capturedArgs = arguments;
}
testFunction('foo', 'bar');
expect(j$.matchersUtil.contains(capturedArgs, 'bar')).toBe(true);
expect(jasmineUnderTest.matchersUtil.contains(capturedArgs, 'bar')).toBe(true);
});
});
@@ -360,7 +513,7 @@ describe("matchersUtil", function() {
it("builds an English sentence for a failure case", function() {
var actual = "foo",
name = "toBar",
message = j$.matchersUtil.buildFailureMessage(name, false, actual);
message = jasmineUnderTest.matchersUtil.buildFailureMessage(name, false, actual);
expect(message).toEqual("Expected 'foo' to bar.");
});
@@ -369,7 +522,7 @@ describe("matchersUtil", function() {
var actual = "foo",
name = "toBar",
isNot = true,
message = message = j$.matchersUtil.buildFailureMessage(name, isNot, actual);
message = message = jasmineUnderTest.matchersUtil.buildFailureMessage(name, isNot, actual);
expect(message).toEqual("Expected 'foo' not to bar.");
});
@@ -377,7 +530,7 @@ describe("matchersUtil", function() {
it("builds an English sentence for an arbitrary array of expected arguments", function() {
var actual = "foo",
name = "toBar",
message = j$.matchersUtil.buildFailureMessage(name, false, actual, "quux", "corge");
message = jasmineUnderTest.matchersUtil.buildFailureMessage(name, false, actual, "quux", "corge");
expect(message).toEqual("Expected 'foo' to bar 'quux', 'corge'.");
});

View File

@@ -1,6 +1,6 @@
describe("toBeCloseTo", function() {
it("passes when within two decimal places by default", function() {
var matcher = j$.matchers.toBeCloseTo(),
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
result;
result = matcher.compare(0, 0);
@@ -11,7 +11,7 @@ describe("toBeCloseTo", function() {
});
it("fails when not within two decimal places by default", function() {
var matcher = j$.matchers.toBeCloseTo(),
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
result;
result = matcher.compare(0, 0.01);
@@ -19,7 +19,7 @@ describe("toBeCloseTo", function() {
});
it("accepts an optional precision argument", function() {
var matcher = j$.matchers.toBeCloseTo(),
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
result;
result = matcher.compare(0, 0.1, 0);
@@ -30,7 +30,7 @@ describe("toBeCloseTo", function() {
});
it("rounds expected values", function() {
var matcher = j$.matchers.toBeCloseTo(),
var matcher = jasmineUnderTest.matchers.toBeCloseTo(),
result;
result = matcher.compare(1.23, 1.229);

View File

@@ -1,6 +1,6 @@
describe("toBeDefined", function() {
it("matches for defined values", function() {
var matcher = j$.matchers.toBeDefined(),
var matcher = jasmineUnderTest.matchers.toBeDefined(),
result;
@@ -9,7 +9,7 @@ describe("toBeDefined", function() {
});
it("fails when matching undefined values", function() {
var matcher = j$.matchers.toBeDefined(),
var matcher = jasmineUnderTest.matchers.toBeDefined(),
result;
result = matcher.compare(void 0);

View File

@@ -1,6 +1,6 @@
describe("toBeFalsy", function() {
it("passes for 'falsy' values", function() {
var matcher = j$.matchers.toBeFalsy(),
var matcher = jasmineUnderTest.matchers.toBeFalsy(),
result;
result = matcher.compare(false);
@@ -20,7 +20,7 @@ describe("toBeFalsy", function() {
});
it("fails for 'truthy' values", function() {
var matcher = j$.matchers.toBeFalsy(),
var matcher = jasmineUnderTest.matchers.toBeFalsy(),
result;
result = matcher.compare(true);

View File

@@ -0,0 +1,29 @@
describe("toBeGreaterThanOrEqual", function() {
it("passes when actual >= expected", function() {
var matcher = jasmineUnderTest.matchers.toBeGreaterThanOrEqual(),
result;
result = matcher.compare(2, 1);
expect(result.pass).toBe(true);
result = matcher.compare(1, 1);
expect(result.pass).toBe(true);
result = matcher.compare(1.0000001, 1);
expect(result.pass).toBe(true);
result = matcher.compare(1.0, 1.0);
expect(result.pass).toBe(true);
})
it("fails when actual < expected", function() {
var matcher = jasmineUnderTest.matchers.toBeGreaterThanOrEqual(),
result;
result = matcher.compare(1, 2);
expect(result.pass).toBe(false);
result = matcher.compare(1, 1.0000001);
expect(result.pass).toBe(false);
})
});

View File

@@ -1,6 +1,6 @@
describe("toBeGreaterThan", function() {
it("passes when actual > expected", function() {
var matcher = j$.matchers.toBeGreaterThan(),
var matcher = jasmineUnderTest.matchers.toBeGreaterThan(),
result;
result = matcher.compare(2, 1);
@@ -8,7 +8,7 @@ describe("toBeGreaterThan", function() {
});
it("fails when actual <= expected", function() {
var matcher = j$.matchers.toBeGreaterThan(),
var matcher = jasmineUnderTest.matchers.toBeGreaterThan(),
result;
result = matcher.compare(1, 1);

View File

@@ -0,0 +1,29 @@
describe("toBeLessThanOrEqual", function() {
it("passes when actual <= expected", function() {
var matcher = jasmineUnderTest.matchers.toBeLessThanOrEqual(),
result;
result = matcher.compare(1, 2);
expect(result.pass).toBe(true);
result = matcher.compare(1, 1);
expect(result.pass).toBe(true);
result = matcher.compare(1, 1.0000001);
expect(result.pass).toBe(true);
result = matcher.compare(1.0, 1.0);
expect(result.pass).toBe(true);
});
it("fails when actual < expected", function() {
var matcher = jasmineUnderTest.matchers.toBeLessThanOrEqual(),
result;
result = matcher.compare(2, 1);
expect(result.pass).toBe(false);
result = matcher.compare(1.0000001, 1);
expect(result.pass).toBe(false);
});
});

View File

@@ -1,6 +1,6 @@
describe("toBeLessThan", function() {
it("passes when actual < expected", function() {
var matcher = j$.matchers.toBeLessThan(),
var matcher = jasmineUnderTest.matchers.toBeLessThan(),
result;
result = matcher.compare(1, 2);
@@ -8,7 +8,7 @@ describe("toBeLessThan", function() {
});
it("fails when actual <= expected", function() {
var matcher = j$.matchers.toBeLessThan(),
var matcher = jasmineUnderTest.matchers.toBeLessThan(),
result;
result = matcher.compare(1, 1);

View File

@@ -1,6 +1,6 @@
describe("toBeNaN", function() {
it("passes for NaN with a custom .not fail", function() {
var matcher = j$.matchers.toBeNaN(),
var matcher = jasmineUnderTest.matchers.toBeNaN(),
result;
result = matcher.compare(Number.NaN);
@@ -9,7 +9,7 @@ describe("toBeNaN", function() {
});
it("fails for anything not a NaN", function() {
var matcher = j$.matchers.toBeNaN(),
var matcher = jasmineUnderTest.matchers.toBeNaN(),
result;
result = matcher.compare(1);
@@ -29,7 +29,7 @@ describe("toBeNaN", function() {
});
it("has a custom message on failure", function() {
var matcher = j$.matchers.toBeNaN(),
var matcher = jasmineUnderTest.matchers.toBeNaN(),
result = matcher.compare(0);
expect(result.message()).toEqual("Expected 0 to be NaN.");

View File

@@ -0,0 +1,31 @@
describe("toBeNegativeInfinity", function() {
it("fails for anything that isn't -Infinity", function() {
var matcher = jasmineUnderTest.matchers.toBeNegativeInfinity(),
result;
result = matcher.compare(1);
expect(result.pass).toBe(false);
result = matcher.compare(Number.NaN);
expect(result.pass).toBe(false);
result = matcher.compare(null);
expect(result.pass).toBe(false);
});
it("has a custom message on failure", function() {
var matcher = jasmineUnderTest.matchers.toBeNegativeInfinity(),
result = matcher.compare(0);
expect(result.message()).toEqual("Expected 0 not to be -Infinity.")
});
it("succeeds for -Infinity", function() {
var matcher = jasmineUnderTest.matchers.toBeNegativeInfinity(),
result = matcher.compare(Number.NEGATIVE_INFINITY);
expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected actual to be -Infinity.")
});
});

View File

@@ -1,6 +1,6 @@
describe("toBeNull", function() {
it("passes for null", function() {
var matcher = j$.matchers.toBeNull(),
var matcher = jasmineUnderTest.matchers.toBeNull(),
result;
result = matcher.compare(null);
@@ -8,7 +8,7 @@ describe("toBeNull", function() {
});
it("fails for non-null", function() {
var matcher = j$.matchers.toBeNull(),
var matcher = jasmineUnderTest.matchers.toBeNull(),
result;
result = matcher.compare('foo');

View File

@@ -0,0 +1,31 @@
describe("toBePositiveInfinity", function() {
it("fails for anything that isn't Infinity", function() {
var matcher = jasmineUnderTest.matchers.toBePositiveInfinity(),
result;
result = matcher.compare(1);
expect(result.pass).toBe(false);
result = matcher.compare(Number.NaN);
expect(result.pass).toBe(false);
result = matcher.compare(null);
expect(result.pass).toBe(false);
});
it("has a custom message on failure", function() {
var matcher = jasmineUnderTest.matchers.toBePositiveInfinity(),
result = matcher.compare(0);
expect(result.message()).toEqual("Expected 0 not to be Infinity.")
});
it("succeeds for Infinity", function() {
var matcher = jasmineUnderTest.matchers.toBePositiveInfinity(),
result = matcher.compare(Number.POSITIVE_INFINITY);
expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected actual to be Infinity.")
});
});

View File

@@ -1,6 +1,6 @@
describe("toBe", function() {
it("passes when actual === expected", function() {
var matcher = j$.matchers.toBe(),
var matcher = jasmineUnderTest.matchers.toBe(),
result;
result = matcher.compare(1, 1);
@@ -8,7 +8,7 @@ describe("toBe", function() {
});
it("fails when actual !== expected", function() {
var matcher = j$.matchers.toBe(),
var matcher = jasmineUnderTest.matchers.toBe(),
result;
result = matcher.compare(1, 2);

View File

@@ -1,6 +1,6 @@
describe("toBeTruthy", function() {
it("passes for 'truthy' values", function() {
var matcher = j$.matchers.toBeTruthy(),
var matcher = jasmineUnderTest.matchers.toBeTruthy(),
result;
result = matcher.compare(true);
@@ -17,7 +17,7 @@ describe("toBeTruthy", function() {
});
it("fails for 'falsy' values", function() {
var matcher = j$.matchers.toBeTruthy(),
var matcher = jasmineUnderTest.matchers.toBeTruthy(),
result;
result = matcher.compare(false);

View File

@@ -1,6 +1,6 @@
describe("toBeUndefined", function() {
it("passes for undefined values", function() {
var matcher = j$.matchers.toBeUndefined(),
var matcher = jasmineUnderTest.matchers.toBeUndefined(),
result;
result = matcher.compare(void 0);
@@ -9,7 +9,7 @@ describe("toBeUndefined", function() {
});
it("fails when matching defined values", function() {
var matcher = j$.matchers.toBeUndefined(),
var matcher = jasmineUnderTest.matchers.toBeUndefined(),
result;
result = matcher.compare('foo');

View File

@@ -1,9 +1,9 @@
describe("toContain", function() {
it("delegates to j$.matchersUtil.contains", function() {
it("delegates to jasmineUnderTest.matchersUtil.contains", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
},
matcher = j$.matchers.toContain(util),
matcher = jasmineUnderTest.matchers.toContain(util),
result;
result = matcher.compare("ABC", "B");
@@ -11,12 +11,12 @@ describe("toContain", function() {
expect(result.pass).toBe(true);
});
it("delegates to j$.matchersUtil.contains, passing in equality testers if present", function() {
it("delegates to jasmineUnderTest.matchersUtil.contains, passing in equality testers if present", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
},
customEqualityTesters = ['a', 'b'],
matcher = j$.matchers.toContain(util, customEqualityTesters),
matcher = jasmineUnderTest.matchers.toContain(util, customEqualityTesters),
result;
result = matcher.compare("ABC", "B");

View File

@@ -1,28 +1,516 @@
describe("toEqual", function() {
"use strict";
function compareEquals(actual, expected) {
var util = jasmineUnderTest.matchersUtil,
matcher = jasmineUnderTest.matchers.toEqual(util);
var result = matcher.compare(actual, expected);
return result;
}
it("delegates to equals function", function() {
var util = {
equals: jasmine.createSpy('delegated-equals').and.returnValue(true)
equals: jasmine.createSpy('delegated-equals').and.returnValue(true),
buildFailureMessage: function() {
return 'does not matter'
},
DiffBuilder: jasmineUnderTest.matchersUtil.DiffBuilder
},
matcher = j$.matchers.toEqual(util),
matcher = jasmineUnderTest.matchers.toEqual(util),
result;
result = matcher.compare(1, 1);
expect(util.equals).toHaveBeenCalledWith(1, 1, []);
expect(util.equals).toHaveBeenCalledWith(1, 1, [], jasmine.anything());
expect(result.pass).toBe(true);
});
it("delegates custom equality testers, if present", function() {
var util = {
equals: jasmine.createSpy('delegated-equals').and.returnValue(true)
equals: jasmine.createSpy('delegated-equals').and.returnValue(true),
buildFailureMessage: function() {
return 'does not matter'
},
DiffBuilder: jasmineUnderTest.matchersUtil.DiffBuilder
},
customEqualityTesters = ['a', 'b'],
matcher = j$.matchers.toEqual(util, customEqualityTesters),
matcher = jasmineUnderTest.matchers.toEqual(util, customEqualityTesters),
result;
result = matcher.compare(1, 1);
expect(util.equals).toHaveBeenCalledWith(1, 1, ['a', 'b']);
expect(util.equals).toHaveBeenCalledWith(1, 1, ['a', 'b'], jasmine.anything());
expect(result.pass).toBe(true);
});
it("reports the difference between objects that are not equal", function() {
var actual = {x: 1, y: 3},
expected = {x: 2, y: 3},
message = "Expected $.x = 1 to equal 2.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports the difference between nested objects that are not equal", function() {
var actual = {x: {y: 1}},
expected = {x: {y: 2}},
message = "Expected $.x.y = 1 to equal 2.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("formats property access so that it's valid JavaScript", function() {
var actual = {'my prop': 1},
expected = {'my prop': 2},
message = "Expected $['my prop'] = 1 to equal 2.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports missing properties", function() {
var actual = {x: {}},
expected = {x: {y: 1}},
message =
"Expected $.x to have properties\n" +
" y: 1";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports extra properties", function() {
var actual = {x: {y: 1, z: 2}},
expected = {x: {}},
message =
"Expected $.x not to have properties\n" +
" y: 1\n" +
" z: 2";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("pretty-prints properties", function() {
var actual = {x: {y: 'foo bar'}},
expected = {x: {}},
message =
"Expected $.x not to have properties\n" +
" y: 'foo bar'"
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports extra and missing properties together", function() {
var actual = {x: {y: 1, z: 2, f: 4}},
expected = {x: {y: 1, z: 2, g: 3}},
message =
"Expected $.x to have properties\n" +
" g: 3\n" +
"Expected $.x not to have properties\n" +
" f: 4";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports extra and missing properties of the root-level object", function() {
var actual = {x: 1},
expected = {a: 1},
message =
"Expected object to have properties\n" +
" a: 1\n" +
"Expected object not to have properties\n" +
" x: 1";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports multiple incorrect values", function() {
var actual = {x: 1, y: 2},
expected = {x: 3, y: 4},
message =
"Expected $.x = 1 to equal 3.\n" +
"Expected $.y = 2 to equal 4.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatch between actual child object and expected child number", function() {
var actual = {x: {y: 2}},
expected = {x: 1},
message = "Expected $.x = Object({ y: 2 }) to equal 1.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("uses the default failure message if actual is not an object", function() {
var actual = 1,
expected = {x: {}},
message = "Expected 1 to equal Object({ x: Object({ }) }).";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("uses the default failure message if expected is not an object", function() {
var actual = {x: {}},
expected = 1,
message = "Expected Object({ x: Object({ }) }) to equal 1.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("uses the default failure message given arrays with different lengths", function() {
var actual = [1, 2],
expected = [1, 2, 3],
message =
"Expected [ 1, 2 ] to equal [ 1, 2, 3 ].";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports a mismatch between elements of equal-length arrays", function() {
var actual = [1, 2, 5],
expected = [1, 2, 3],
message = "Expected $[2] = 5 to equal 3.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports a mismatch between multiple array elements", function() {
var actual = [2, 2, 5],
expected = [1, 2, 3],
message =
"Expected $[0] = 2 to equal 1.\n" +
"Expected $[2] = 5 to equal 3.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports a mismatch between properties of objects in arrays", function() {
var actual = [{x: 1}],
expected = [{x: 2}],
message = "Expected $[0].x = 1 to equal 2.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports a mismatch between arrays in objects", function() {
var actual = {x: [1]},
expected = {x: [2]},
message =
"Expected $.x[0] = 1 to equal 2.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches between nested arrays", function() {
var actual = [[1]],
expected = [[2]],
message =
"Expected $[0][0] = 1 to equal 2.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches involving NaN", function() {
var actual = {x: 0},
expected = {x: 0/0},
message = "Expected $.x = 0 to equal NaN.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches involving regular expressions", function() {
var actual = {x: '1'},
expected = {x: /1/},
message = "Expected $.x = '1' to equal /1/.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches involving infinities", function() {
var actual = {x: 0},
expected = {x: 1/0},
message = "Expected $.x = 0 to equal Infinity.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches involving booleans", function() {
var actual = {x: false},
expected = {x: true},
message = "Expected $.x = false to equal true.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches involving strings", function() {
var actual = {x: 'foo'},
expected = {x: 'bar'},
message = "Expected $.x = 'foo' to equal 'bar'.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches involving undefined", function() {
var actual = {x: void 0},
expected = {x: 0},
message = "Expected $.x = undefined to equal 0.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches involving null", function() {
var actual = {x: null},
expected = {x: 0},
message = "Expected $.x = null to equal 0.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches between objects with different constructors", function () {
function Foo() {}
function Bar() {}
var actual = {x: new Foo()},
expected = {x: new Bar()},
message = "Expected $.x to be a kind of Bar, but was Foo({ }).";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports type mismatches at the root level", function () {
function Foo() {}
function Bar() {}
var actual = new Foo(),
expected = new Bar(),
message = "Expected object to be a kind of Bar, but was Foo({ }).";
expect(compareEquals(actual, expected).message).toEqual(message);
});
function constructorIsNotEnumerable() {
// in IE8, the constructor property is not enumerable, even if it is an
// own property of the object.
// Objects that differ only by an own `constructor` property are thus
// considered equal in IE8.
for (var key in {constructor: 1}) {
return false;
}
return true;
}
it("reports mismatches between objects with their own constructor property", function () {
if (constructorIsNotEnumerable()) {
return;
}
function Foo() {}
function Bar() {}
var actual = {x: {constructor: 'blerf'}},
expected = {x: {constructor: 'ftarrh'}},
message = "Expected $.x.constructor = 'blerf' to equal 'ftarrh'.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches between an object with a real constructor and one with its own constructor property", function () {
if (constructorIsNotEnumerable()) {
return;
}
function Foo() {}
function Bar() {}
var actual = {x: {}},
expected = {x: {constructor: 'ftarrh'}},
message =
"Expected $.x to have properties\n" +
" constructor: 'ftarrh'";
expect(compareEquals(actual, expected).message).toEqual(message);
expect(compareEquals(expected, actual).message).toEqual(
"Expected $.x not to have properties\n constructor: 'ftarrh'"
);
});
it("reports mismatches between 0 and -0", function() {
var actual = {x: 0},
expected = {x: -0},
message = "Expected $.x = 0 to equal -0.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches between Errors", function() {
var actual = {x: new Error("the error you got")},
expected = {x: new Error("the error you want")},
message = "Expected $.x = Error: the error you got to equal Error: the error you want.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches between Functions", function() {
var actual = {x: function() {}},
expected = {x: function() {}},
message = "Expected $.x = Function to equal Function.";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("does not report deep mismatches within Sets", function() {
// TODO: implement deep comparison of set elements
jasmine.getEnv().requireFunctioningSets();
var actual = new Set([1]),
expected = new Set([2]),
message = 'Expected Set( 1 ) to equal Set( 2 ).';
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches between Sets nested in objects", function() {
jasmine.getEnv().requireFunctioningSets();
var actual = {sets: [new Set([1])]},
expected = {sets: [new Set([2])]},
message = "Expected $.sets[0] = Set( 1 ) to equal Set( 2 ).";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches between Sets of different lengths", function() {
jasmine.getEnv().requireFunctioningSets();
var actual = new Set([1, 2]),
expected = new Set([2]),
message = 'Expected Set( 1, 2 ) to equal Set( 2 ).';
expect(compareEquals(actual, expected).message).toEqual(message);
});
function isNotRunningInBrowser() {
return typeof document === 'undefined'
}
it("reports mismatches between DOM nodes with different tags", function() {
if(isNotRunningInBrowser()) {
return;
}
var actual = {a: document.createElement('div')},
expected = {a: document.createElement('p')},
message = 'Expected $.a = HTMLNode to equal HTMLNode.';
expect(compareEquals(actual, expected).message).toEqual(message);
});
it('reports mismatches between DOM nodes with different content', function() {
if(isNotRunningInBrowser()) {
return;
}
var nodeA = document.createElement('div'),
nodeB = document.createElement('div');
nodeA.innerText = 'foo'
nodeB.innerText = 'bar'
var actual = {a: nodeA},
expected = {a: nodeB},
message = 'Expected $.a = HTMLNode to equal HTMLNode.';
expect(compareEquals(actual, expected).message).toEqual(message);
})
it("reports mismatches between a DOM node and a bare Object", function() {
if(isNotRunningInBrowser()) {
return;
}
var actual = {a: document.createElement('div')},
expected = {a: {}},
message = 'Expected $.a = HTMLNode to equal Object({ }).';
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports asymmetric mismatches", function() {
var actual = {a: 1},
expected = {a: jasmineUnderTest.any(String)},
message = 'Expected $.a = 1 to equal <jasmine.any(String)>.';
expect(compareEquals(actual, expected).message).toEqual(message);
expect(compareEquals(actual, expected).pass).toBe(false)
});
it("reports asymmetric mismatches when the asymmetric comparand is the actual value", function() {
var actual = {a: jasmineUnderTest.any(String)},
expected = {a: 1},
message = 'Expected $.a = <jasmine.any(String)> to equal 1.';
expect(compareEquals(actual, expected).message).toEqual(message);
expect(compareEquals(actual, expected).pass).toBe(false)
});
it("does not report a mismatch when asymmetric matchers are satisfied", function() {
var actual = {a: 'a'},
expected = {a: jasmineUnderTest.any(String)},
message = 'Expected $.a = 1 to equal <jasmine.any(String)>.';
expect(compareEquals(actual, expected).pass).toBe(true)
});
it("works on big complex stuff", function() {
var actual = {
foo: [
{bar: 1, things: ['a', 'b']},
{bar: 2, things: ['a', 'b']}
],
baz: [
{a: {b: 1}}
],
quux: 1,
nan: 0,
aRegexp: 'hi',
inf: -1/0,
boolean: false,
notDefined: 0,
aNull: void 0
}
var expected = {
foo: [
{bar: 2, things: ['a', 'b', 'c']},
{bar: 2, things: ['a', 'd']}
],
baz: [
{a: {b: 1, c: 1}}
],
quux: [],
nan: 0/0,
aRegexp: /hi/,
inf: 1/0,
boolean: true,
notDefined: void 0,
aNull: null
}
var message =
'Expected $.foo[0].bar = 1 to equal 2.\n' +
"Expected $.foo[0].things = [ 'a', 'b' ] to equal [ 'a', 'b', 'c' ].\n" +
"Expected $.foo[1].things[1] = 'b' to equal 'd'.\n" +
'Expected $.baz[0].a to have properties\n' +
' c: 1\n' +
'Expected $.quux = 1 to equal [ ].\n' +
'Expected $.nan = 0 to equal NaN.\n' +
"Expected $.aRegexp = 'hi' to equal /hi/.\n" +
'Expected $.inf = -Infinity to equal Infinity.\n' +
'Expected $.boolean = false to equal true.\n' +
'Expected $.notDefined = 0 to equal undefined.\n' +
'Expected $.aNull = undefined to equal null.'
expect(compareEquals(actual, expected).message).toEqual(message);
})
});

View File

@@ -0,0 +1,99 @@
describe("toHaveBeenCalledBefore", function() {
it("throws an exception when the actual is not a spy", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
fn = function() {},
secondSpy = jasmineUnderTest.createSpy('second spy');
expect(function() { matcher.compare(fn, secondSpy) }).toThrowError(Error, /Expected a spy, but got Function./);
});
it("throws an exception when the expected is not a spy", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
firstSpy = jasmineUnderTest.createSpy('first spy'),
fn = function() {};
expect(function() { matcher.compare(firstSpy, fn) }).toThrowError(Error, /Expected a spy, but got Function./);
});
it("fails when the actual was not called", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
firstSpy = jasmineUnderTest.createSpy('first spy'),
secondSpy = jasmineUnderTest.createSpy('second spy');
secondSpy();
result = matcher.compare(firstSpy, secondSpy);
expect(result.pass).toBe(false);
expect(result.message).toMatch(/Expected spy first spy to have been called./);
});
it("fails when the expected was not called", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
firstSpy = jasmineUnderTest.createSpy('first spy'),
secondSpy = jasmineUnderTest.createSpy('second spy');
firstSpy();
result = matcher.compare(firstSpy, secondSpy);
expect(result.pass).toBe(false);
expect(result.message).toMatch(/Expected spy second spy to have been called./);
});
it("fails when the actual is called after the expected", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
firstSpy = jasmineUnderTest.createSpy('first spy'),
secondSpy = jasmineUnderTest.createSpy('second spy'),
result;
secondSpy();
firstSpy();
result = matcher.compare(firstSpy, secondSpy);
expect(result.pass).toBe(false);
expect(result.message).toEqual('Expected spy first spy to have been called before spy second spy');
});
it("fails when the actual is called before and after the expected", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
firstSpy = jasmineUnderTest.createSpy('first spy'),
secondSpy = jasmineUnderTest.createSpy('second spy'),
result;
firstSpy();
secondSpy();
firstSpy();
result = matcher.compare(firstSpy, secondSpy);
expect(result.pass).toBe(false);
expect(result.message).toEqual('Expected latest call to spy first spy to have been called before first call to spy second spy (no interleaved calls)');
});
it("fails when the expected is called before and after the actual", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
firstSpy = jasmineUnderTest.createSpy('first spy'),
secondSpy = jasmineUnderTest.createSpy('second spy'),
result;
secondSpy();
firstSpy();
secondSpy();
result = matcher.compare(firstSpy, secondSpy);
expect(result.pass).toBe(false);
expect(result.message).toEqual('Expected first call to spy second spy to have been called after latest call to spy first spy (no interleaved calls)');
});
it("passes when the actual is called before the expected", function() {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
firstSpy = jasmineUnderTest.createSpy('first spy'),
secondSpy = jasmineUnderTest.createSpy('second spy'),
result;
firstSpy();
secondSpy();
result = matcher.compare(firstSpy, secondSpy);
expect(result.pass).toBe(true);
expect(result.message).toEqual('Expected spy first spy to not have been called before spy second spy, but it was');
});
});

View File

@@ -1,7 +1,7 @@
describe("toHaveBeenCalled", function() {
it("passes when the actual was called, with a custom .not fail message", function() {
var matcher = j$.matchers.toHaveBeenCalled(),
calledSpy = j$.createSpy('called-spy'),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
calledSpy = jasmineUnderTest.createSpy('called-spy'),
result;
calledSpy();
@@ -12,8 +12,8 @@ describe("toHaveBeenCalled", function() {
});
it("fails when the actual was not called", function() {
var matcher = j$.matchers.toHaveBeenCalled(),
uncalledSpy = j$.createSpy('uncalled spy'),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
result;
result = matcher.compare(uncalledSpy);
@@ -21,22 +21,22 @@ describe("toHaveBeenCalled", function() {
});
it("throws an exception when the actual is not a spy", function() {
var matcher = j$.matchers.toHaveBeenCalled(),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
fn = function() {};
expect(function() { matcher.compare(fn) }).toThrow(new Error("Expected a spy, but got Function."));
expect(function() { matcher.compare(fn) }).toThrowError(Error, /Expected a spy, but got Function./);
});
it("throws an exception when invoked with any arguments", function() {
var matcher = j$.matchers.toHaveBeenCalled(),
spy = j$.createSpy('sample spy');
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
spy = jasmineUnderTest.createSpy('sample spy');
expect(function() { matcher.compare(spy, 'foo') }).toThrow(new Error("toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith"));
expect(function() { matcher.compare(spy, 'foo') }).toThrowError(Error, /Does not take arguments, use toHaveBeenCalledWith/);
});
it("has a custom message on failure", function() {
var matcher = j$.matchers.toHaveBeenCalled(),
spy = j$.createSpy('sample-spy'),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalled(),
spy = jasmineUnderTest.createSpy('sample-spy'),
result;
result = matcher.compare(spy);

View File

@@ -1,7 +1,14 @@
describe("toHaveBeenCalledTimes", function() {
it("passes when the actual 0 matches the expected 0 ", function () {
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
calledSpy = jasmineUnderTest.createSpy('called-spy'),
result;
result = matcher.compare(calledSpy, 0);
expect(result.pass).toBeTruthy();
});
it("passes when the actual matches the expected", function() {
var matcher = j$.matchers.toHaveBeenCalledTimes(),
calledSpy = j$.createSpy('called-spy'),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
calledSpy = jasmineUnderTest.createSpy('called-spy'),
result;
calledSpy();
@@ -10,19 +17,19 @@ describe("toHaveBeenCalledTimes", function() {
});
it("fails when expected numbers is not supplied", function(){
var matcher = j$.matchers.toHaveBeenCalledTimes(),
spy = j$.createSpy('spy'),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
spy = jasmineUnderTest.createSpy('spy'),
result;
spy();
expect(function() {
matcher.compare(spy);
}).toThrowError('Expected times failed is required as an argument.');
}).toThrowError(/The expected times failed is a required argument and must be a number./);
});
it("fails when the actual was called less than the expected", function() {
var matcher = j$.matchers.toHaveBeenCalledTimes(),
uncalledSpy = j$.createSpy('uncalled spy'),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
result;
result = matcher.compare(uncalledSpy, 2);
@@ -30,8 +37,8 @@ describe("toHaveBeenCalledTimes", function() {
});
it("fails when the actual was called more than expected", function() {
var matcher = j$.matchers.toHaveBeenCalledTimes(),
uncalledSpy = j$.createSpy('uncalled spy'),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
result;
uncalledSpy();
@@ -42,17 +49,17 @@ describe("toHaveBeenCalledTimes", function() {
});
it("throws an exception when the actual is not a spy", function() {
var matcher = j$.matchers.toHaveBeenCalledTimes(),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
fn = function() {};
expect(function() {
matcher.compare(fn);
}).toThrowError("Expected a spy, but got Function.");
}).toThrowError(/Expected a spy, but got Function./);
});
it("has a custom message on failure that tells it was called only once", function() {
var matcher = j$.matchers.toHaveBeenCalledTimes(),
spy = j$.createSpy('sample-spy'),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
spy = jasmineUnderTest.createSpy('sample-spy'),
result;
spy();
spy();
@@ -60,13 +67,12 @@ describe("toHaveBeenCalledTimes", function() {
spy();
result = matcher.compare(spy, 1);
expect(result.message).toEqual('Expected spy sample-spy to have been called once. It was called ' + 4 + ' times.');
});
it("has a custom message on failure that tells how many times it was called", function() {
var matcher = j$.matchers.toHaveBeenCalledTimes(),
spy = j$.createSpy('sample-spy'),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledTimes(),
spy = jasmineUnderTest.createSpy('sample-spy'),
result;
spy();
spy();
@@ -74,7 +80,6 @@ describe("toHaveBeenCalledTimes", function() {
spy();
result = matcher.compare(spy, 2);
expect(result.message).toEqual('Expected spy sample-spy to have been called 2 times. It was called ' + 4 + ' times.');
});
});

View File

@@ -1,10 +1,11 @@
describe("toHaveBeenCalledWith", function() {
it("passes when the actual was called with matching parameters", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
},
matcher = j$.matchers.toHaveBeenCalledWith(util),
calledSpy = j$.createSpy('called-spy'),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
calledSpy = jasmineUnderTest.createSpy('called-spy'),
result;
calledSpy('a', 'b');
@@ -19,8 +20,8 @@ describe("toHaveBeenCalledWith", function() {
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
},
customEqualityTesters = [function() { return true; }],
matcher = j$.matchers.toHaveBeenCalledWith(util, customEqualityTesters),
calledSpy = j$.createSpy('called-spy');
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util, customEqualityTesters),
calledSpy = jasmineUnderTest.createSpy('called-spy');
calledSpy('a', 'b');
matcher.compare(calledSpy, 'a', 'b');
@@ -32,8 +33,8 @@ describe("toHaveBeenCalledWith", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
},
matcher = j$.matchers.toHaveBeenCalledWith(util),
uncalledSpy = j$.createSpy('uncalled spy'),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
uncalledSpy = jasmineUnderTest.createSpy('uncalled spy'),
result;
result = matcher.compare(uncalledSpy);
@@ -45,8 +46,8 @@ describe("toHaveBeenCalledWith", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(false)
},
matcher = j$.matchers.toHaveBeenCalledWith(util),
calledSpy = j$.createSpy('called spy'),
matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(util),
calledSpy = jasmineUnderTest.createSpy('called spy'),
result;
calledSpy('a');
@@ -58,9 +59,9 @@ describe("toHaveBeenCalledWith", function() {
});
it("throws an exception when the actual is not a spy", function() {
var matcher = j$.matchers.toHaveBeenCalledWith(),
var matcher = jasmineUnderTest.matchers.toHaveBeenCalledWith(),
fn = function() {};
expect(function() { matcher.compare(fn) }).toThrow(new Error("Expected a spy, but got Function."));
expect(function() { matcher.compare(fn) }).toThrowError(/Expected a spy, but got Function./);
});
});

View File

@@ -1,6 +1,7 @@
describe("toMatch", function() {
it("passes when RegExps are equivalent", function() {
var matcher = j$.matchers.toMatch(),
var matcher = jasmineUnderTest.matchers.toMatch(),
result;
result = matcher.compare(/foo/, /foo/);
@@ -8,7 +9,7 @@ describe("toMatch", function() {
});
it("fails when RegExps are not equivalent", function() {
var matcher = j$.matchers.toMatch(),
var matcher = jasmineUnderTest.matchers.toMatch(),
result;
result = matcher.compare(/bar/, /foo/);
@@ -16,7 +17,7 @@ describe("toMatch", function() {
});
it("passes when the actual matches the expected string as a pattern", function() {
var matcher = j$.matchers.toMatch(),
var matcher = jasmineUnderTest.matchers.toMatch(),
result;
result = matcher.compare('foosball', 'foo');
@@ -24,7 +25,7 @@ describe("toMatch", function() {
});
it("fails when the actual matches the expected string as a pattern", function() {
var matcher = j$.matchers.toMatch(),
var matcher = jasmineUnderTest.matchers.toMatch(),
result;
result = matcher.compare('bar', 'foo');
@@ -32,11 +33,11 @@ describe("toMatch", function() {
});
it("throws an Error when the expected is not a String or RegExp", function() {
var matcher = j$.matchers.toMatch();
var matcher = jasmineUnderTest.matchers.toMatch();
expect(function() {
matcher.compare('foo', { bar: 'baz' });
}).toThrowError('Expected is not a String or a RegExp');
}).toThrowError(/Expected is not a String or a RegExp/);
});
});

View File

@@ -1,47 +1,47 @@
describe("toThrowError", function() {
it("throws an error when the actual is not a function", function() {
var matcher = j$.matchers.toThrowError();
var matcher = jasmineUnderTest.matchers.toThrowError();
expect(function() {
matcher.compare({});
}).toThrowError("Actual is not a Function");
}).toThrowError(/Actual is not a Function/);
});
it("throws an error when the expected is not an Error, string, or RegExp", function() {
var matcher = j$.matchers.toThrowError(),
var matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw new Error("foo");
};
expect(function() {
matcher.compare(fn, 1);
}).toThrowError("Expected is not an Error, string, or RegExp.");
}).toThrowError(/Expected is not an Error, string, or RegExp./);
});
it("throws an error when the expected error type is not an Error", function() {
var matcher = j$.matchers.toThrowError(),
var matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw new Error("foo");
};
expect(function() {
matcher.compare(fn, void 0, "foo");
}).toThrowError("Expected error type is not an Error.");
}).toThrowError(/Expected error type is not an Error./);
});
it("throws an error when the expected error message is not a string or RegExp", function() {
var matcher = j$.matchers.toThrowError(),
var matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw new Error("foo");
};
expect(function() {
matcher.compare(fn, Error, 1);
}).toThrowError("Expected error message is not a string or RegExp.");
}).toThrowError(/Expected error message is not a string or RegExp./);
});
it("fails if actual does not throw at all", function() {
var matcher = j$.matchers.toThrowError(),
var matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
return true;
},
@@ -54,7 +54,7 @@ describe("toThrowError", function() {
});
it("fails if thrown is not an instanceof Error", function() {
var matcher = j$.matchers.toThrowError(),
var matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw 4;
},
@@ -65,8 +65,45 @@ describe("toThrowError", function() {
expect(result.message()).toEqual("Expected function to throw an Error, but it threw 4.");
});
describe("when error is from another frame", function() {
function isNotRunningInBrowser() {
return typeof document === 'undefined'
}
var iframe = null;
afterEach(function() {
if (iframe !== null) {
document.body.removeChild(iframe);
}
});
it("passes if thrown is an instanceof Error regardless of global that contains its constructor", function() {
if (isNotRunningInBrowser() || jasmine.getEnv().phantomVersion < 2 || jasmine.getEnv().ieVersion < 10) {
return;
}
var matcher = jasmineUnderTest.matchers.toThrowError();
iframe = document.body.appendChild(document.createElement("iframe"));
iframe.src = "about:blank";
var iframeDocument = iframe.contentWindow.document;
if (iframeDocument.body) {
iframeDocument.body.appendChild(iframeDocument.createElement("script"))
.textContent = "function method() { throw new Error('foo'); }";
} else {
// older IE
iframeDocument.write("<html><head><script>function method() { throw new Error('foo'); }</script></head></html>");
}
var result = matcher.compare(iframe.contentWindow.method);
expect(result.pass).toBe(true);
expect(result.message).toEqual("Expected function not to throw an Error, but it threw Error.");
});
});
it("fails with the correct message if thrown is a falsy value", function() {
var matcher = j$.matchers.toThrowError(),
var matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw undefined;
},
@@ -78,7 +115,7 @@ describe("toThrowError", function() {
});
it("passes if thrown is a type of Error, but there is no expected error", function() {
var matcher = j$.matchers.toThrowError(),
var matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw new TypeError();
},
@@ -91,7 +128,7 @@ describe("toThrowError", function() {
});
it("passes if thrown is an Error and the expected is the same message", function() {
var matcher = j$.matchers.toThrowError(),
var matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw new Error("foo");
},
@@ -104,7 +141,7 @@ describe("toThrowError", function() {
});
it("fails if thrown is an Error and the expected is not the same message", function() {
var matcher = j$.matchers.toThrowError(),
var matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw new Error("foo");
},
@@ -117,7 +154,7 @@ describe("toThrowError", function() {
});
it("passes if thrown is an Error and the expected is a RegExp that matches the message", function() {
var matcher = j$.matchers.toThrowError(),
var matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw new Error("a long message");
},
@@ -130,7 +167,7 @@ describe("toThrowError", function() {
});
it("fails if thrown is an Error and the expected is a RegExp that does not match the message", function() {
var matcher = j$.matchers.toThrowError(),
var matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw new Error("a long message");
},
@@ -146,7 +183,7 @@ describe("toThrowError", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
},
matcher = j$.matchers.toThrowError(),
matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw new Error();
},
@@ -162,7 +199,7 @@ describe("toThrowError", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
},
matcher = j$.matchers.toThrowError(),
matcher = jasmineUnderTest.matchers.toThrowError(),
CustomError = function CustomError(arg) { arg.x },
fn = function() {
throw new CustomError({ x: 1 });
@@ -181,7 +218,7 @@ describe("toThrowError", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
},
matcher = j$.matchers.toThrowError(),
matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw new Error();
},
@@ -197,7 +234,7 @@ describe("toThrowError", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
},
matcher = j$.matchers.toThrowError(),
matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw new TypeError("foo");
},
@@ -213,7 +250,7 @@ describe("toThrowError", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
},
matcher = j$.matchers.toThrowError(),
matcher = jasmineUnderTest.matchers.toThrowError(),
CustomError = function CustomError(arg) { this.message = arg.message },
fn = function() {
throw new CustomError({message: "foo"});
@@ -232,7 +269,7 @@ describe("toThrowError", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
},
matcher = j$.matchers.toThrowError(),
matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw new TypeError("foo");
},
@@ -248,7 +285,7 @@ describe("toThrowError", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
},
matcher = j$.matchers.toThrowError(),
matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw new TypeError("foo");
},
@@ -264,7 +301,7 @@ describe("toThrowError", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
},
matcher = j$.matchers.toThrowError(),
matcher = jasmineUnderTest.matchers.toThrowError(),
fn = function() {
throw new TypeError("foo");
},

View File

@@ -1,15 +1,16 @@
describe("toThrow", function() {
it("throws an error when the actual is not a function", function() {
var matcher = j$.matchers.toThrow();
var matcher = jasmineUnderTest.matchers.toThrow();
expect(function() {
matcher.compare({});
matcherComparator({});
}).toThrowError("Actual is not a Function");
}).toThrowError(/Actual is not a Function/);
});
it("fails if actual does not throw", function() {
var matcher = j$.matchers.toThrow(),
var matcher = jasmineUnderTest.matchers.toThrow(),
fn = function() {
return true;
},
@@ -25,7 +26,7 @@ describe("toThrow", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
},
matcher = j$.matchers.toThrow(util),
matcher = jasmineUnderTest.matchers.toThrow(util),
fn = function() {
throw 5;
},
@@ -38,7 +39,7 @@ describe("toThrow", function() {
});
it("passes even if what is thrown is falsy", function() {
var matcher = j$.matchers.toThrow(),
var matcher = jasmineUnderTest.matchers.toThrow(),
fn = function() {
throw undefined;
},
@@ -53,7 +54,7 @@ describe("toThrow", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(true)
},
matcher = j$.matchers.toThrow(util),
matcher = jasmineUnderTest.matchers.toThrow(util),
fn = function() {
throw 5;
},
@@ -69,7 +70,7 @@ describe("toThrow", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
},
matcher = j$.matchers.toThrow(util),
matcher = jasmineUnderTest.matchers.toThrow(util),
fn = function() {
throw 5;
},
@@ -85,7 +86,7 @@ describe("toThrow", function() {
var util = {
equals: jasmine.createSpy('delegated-equal').and.returnValue(false)
},
matcher = j$.matchers.toThrow(util),
matcher = jasmineUnderTest.matchers.toThrow(util),
fn = function() {
throw 5;
},

View File

@@ -20,4 +20,8 @@
return /Firefox\/([0-9]{0,})/.exec(userAgent);
});
env.phantomVersion = browserVersion(function(userAgent) {
return /PhantomJS\/([0-9]{0,})/.exec(userAgent);
});
})(jasmine.getEnv());

View File

@@ -0,0 +1,21 @@
(function(env) {
function hasFunctioningSets() {
if (typeof Set === 'undefined') { return false; }
try {
var s = new Set([4]);
if (s.size !== 1) { return false; }
if (s.values().next().value !== 4) { return false; }
return true;
} catch(e) {
return false;
}
}
env.requireFunctioningSets = function() {
if (!hasFunctioningSets()) {
env.pending("Browser has incomplete or missing support for Sets");
}
};
})(jasmine.getEnv());

View File

@@ -1,7 +1,7 @@
(function() {
// By the time onload is called, jasmineRequire will be redefined to point
// to the Jasmine source files (and not jasmine.js). So re-require
window.j$ = jasmineRequire.core(jasmineRequire);
jasmineRequire.html(j$);
jasmineRequire.console(jasmineRequire, j$);
window.jasmineUnderTest = jasmineRequire.core(jasmineRequire);
jasmineRequire.html(jasmineUnderTest);
jasmineRequire.console(jasmineRequire, jasmineUnderTest);
})();

View File

@@ -4,10 +4,10 @@
var glob = require("glob");
var j$Require = require(path.join(__dirname, "../../src/core/requireCore.js"));
var jasmineUnderTestRequire = require(path.join(__dirname, "../../src/core/requireCore.js"));
global.getJasmineRequireObj = function () {
return j$Require;
return jasmineUnderTestRequire;
};
function extend(destination, source) {
@@ -25,9 +25,9 @@
});
}
extend(j$Require, require(path.join(__dirname,"../../src/console/requireConsole.js")));
extend(jasmineUnderTestRequire, require(path.join(__dirname,"../../src/console/requireConsole.js")));
getSourceFiles();
global.j$ = j$Require.core(j$Require);
global.jasmineUnderTest = jasmineUnderTestRequire.core(jasmineUnderTestRequire);
j$Require.console(j$Require, j$);
jasmineUnderTestRequire.console(jasmineUnderTestRequire, jasmineUnderTest);
})();

View File

@@ -1,10 +1,9 @@
describe("New HtmlReporter", function() {
// TODO: Figure out why this isn't rendering...
it("builds the initial DOM elements, including the title banner", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
@@ -29,14 +28,14 @@ describe("New HtmlReporter", function() {
var version = banner.querySelector(".jasmine-version"),
versionText = 'textContent' in version ? version.textContent : version.innerText;
expect(versionText).toEqual(j$.version);
expect(versionText).toEqual(jasmineUnderTest.version);
});
it("builds a single reporter even if initialized multiple times", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
@@ -52,7 +51,7 @@ describe("New HtmlReporter", function() {
it("starts the timer when jasmine begins", function() {
var env = new jasmine.Env(),
startTimerSpy = jasmine.createSpy("start-timer-spy"),
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
createElement: function() { return document.createElement.apply(document, arguments); },
timer: { start: startTimerSpy }
@@ -69,10 +68,10 @@ describe("New HtmlReporter", function() {
console = { error: function(){} };
}
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement('div'),
getContainer = function() {return container;},
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
@@ -95,10 +94,10 @@ describe("New HtmlReporter", function() {
});
it("reports the status symbol of a disabled spec", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
@@ -115,10 +114,10 @@ describe("New HtmlReporter", function() {
});
it("reports the status symbol of a pending spec", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
@@ -134,10 +133,10 @@ describe("New HtmlReporter", function() {
});
it("reports the status symbol of a passing spec", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
@@ -154,10 +153,10 @@ describe("New HtmlReporter", function() {
});
it("reports the status symbol of a failing spec", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
@@ -181,10 +180,10 @@ describe("New HtmlReporter", function() {
describe("when there are suite failures", function () {
it("displays the exceptions in their own alert bars", function(){
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
@@ -196,14 +195,16 @@ describe("New HtmlReporter", function() {
reporter.jasmineStarted({});
reporter.suiteDone({ status: 'failed', failedExpectations: [{ message: 'My After All Exception' }] });
reporter.suiteDone({ status: 'failed', failedExpectations: [{ message: 'My Other Exception' }] });
reporter.jasmineDone({});
reporter.jasmineDone({ failedExpectations: [{ message: 'Global After All Failure' }, { message: 'Other Global' }] });
var alertBars = container.querySelectorAll(".jasmine-alert .jasmine-bar");
expect(alertBars.length).toEqual(3);
expect(alertBars.length).toEqual(5);
expect(alertBars[1].innerHTML).toMatch(/My After All Exception/);
expect(alertBars[1].getAttribute("class")).toEqual('jasmine-bar jasmine-errored');
expect(alertBars[2].innerHTML).toMatch(/My Other Exception/);
expect(alertBars[3].innerHTML).toMatch(/Global After All Failure/);
expect(alertBars[4].innerHTML).toMatch(/Other Global/);
});
});
@@ -212,10 +213,10 @@ describe("New HtmlReporter", function() {
if (!window.console) {
window.console = { error: function(){} };
}
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement('div'),
getContainer = function() {return container;},
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
@@ -247,11 +248,11 @@ describe("New HtmlReporter", function() {
});
it("reports the run time", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
timer = jasmine.createSpyObj('timer', ['start', 'elapsed']),
getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
@@ -271,10 +272,10 @@ describe("New HtmlReporter", function() {
});
it("reports the suite and spec names with status", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
@@ -365,12 +366,12 @@ describe("New HtmlReporter", function() {
});
it("has an options menu", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() {
return container;
},
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() {
@@ -400,12 +401,12 @@ describe("New HtmlReporter", function() {
describe("UI for raising/catching exceptions", function() {
it("should be unchecked if the env is catching", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() {
return container;
},
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() {
@@ -424,12 +425,12 @@ describe("New HtmlReporter", function() {
});
it("should be checked if the env is not catching", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() {
return container;
},
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() {
@@ -449,13 +450,13 @@ describe("New HtmlReporter", function() {
});
it("should affect the query param for catching exceptions", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
exceptionsClickHandler = jasmine.createSpy("raise exceptions checked"),
getContainer = function() {
return container;
},
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
onRaiseExceptionsClick: exceptionsClickHandler,
@@ -478,12 +479,12 @@ describe("New HtmlReporter", function() {
describe("UI for throwing errors on expectation failures", function() {
it("should be unchecked if not throwing", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() {
return container;
},
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() {
@@ -502,12 +503,12 @@ describe("New HtmlReporter", function() {
});
it("should be checked if throwing", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() {
return container;
},
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() {
@@ -528,13 +529,13 @@ describe("New HtmlReporter", function() {
});
it("should affect the query param for throw expectation failures", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
throwingExceptionHandler = jasmine.createSpy('throwingExceptions'),
getContainer = function() {
return container;
},
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
onThrowExpectationsClick: throwingExceptionHandler,
@@ -558,12 +559,12 @@ describe("New HtmlReporter", function() {
describe("UI for running tests in random order", function() {
it("should be unchecked if not randomizing", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() {
return container;
},
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() {
@@ -582,12 +583,12 @@ describe("New HtmlReporter", function() {
});
it("should be checked if randomizing", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() {
return container;
},
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() {
@@ -607,13 +608,13 @@ describe("New HtmlReporter", function() {
});
it("should affect the query param for random tests", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
randomHandler = jasmine.createSpy('randomHandler'),
getContainer = function() {
return container;
},
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
onRandomClick: randomHandler,
@@ -635,12 +636,12 @@ describe("New HtmlReporter", function() {
});
it("should show the seed bar if randomizing", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() {
return container;
},
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() {
@@ -667,12 +668,12 @@ describe("New HtmlReporter", function() {
});
it("should not show the current seed bar if not randomizing", function() {
var env = new j$.Env(),
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
getContainer = function() {
return container;
},
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() {
@@ -690,14 +691,49 @@ describe("New HtmlReporter", function() {
expect(seedBar).toBeNull();
});
it("should include the random query param in the jasmine-skipped link when randomizing", function(){
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: function() { return container; },
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
});
reporter.initialize();
reporter.jasmineStarted({ totalSpecsDefined: 1 });
reporter.jasmineDone({ order: { random: true } });
var skippedLink = container.querySelector(".jasmine-skipped a");
expect(skippedLink.getAttribute('href')).toEqual('?random=true');
});
it("should not include the random query param in the jasmine-skipped link when not randomizing", function(){
var env = new jasmineUnderTest.Env(),
container = document.createElement("div"),
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: function() { return container; },
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
});
reporter.initialize();
reporter.jasmineStarted({ totalSpecsDefined: 1 });
reporter.jasmineDone();
var skippedLink = container.querySelector(".jasmine-skipped a");
expect(skippedLink.getAttribute('href')).toEqual('?');
});
});
it("shows a message if no specs are run", function(){
var env, container, reporter;
env = new j$.Env();
env = new jasmineUnderTest.Env();
container = document.createElement("div");
var getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
@@ -716,10 +752,10 @@ describe("New HtmlReporter", function() {
describe("and all specs pass", function() {
var env, container, reporter;
beforeEach(function() {
env = new j$.Env();
env = new jasmineUnderTest.Env();
container = document.createElement("div");
var getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
@@ -768,13 +804,71 @@ describe("New HtmlReporter", function() {
});
});
describe("and there are disabled specs", function() {
var env, container, reporter, reporterConfig, specStatus;
beforeEach(function() {
env = new jasmineUnderTest.Env();
container = document.createElement("div");
reporterConfig = {
env: env,
getContainer: function() { return container; },
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
};
specStatus = {
id: 123,
description: "with a disabled spec",
fullName: "A Suite with a disabled spec",
status: "disabled",
passedExpectations: [],
failedExpectations: []
};
});
describe("when the specs are not filtered", function() {
beforeEach(function() {
reporterConfig.filterSpecs = false;
reporter = new jasmineUnderTest.HtmlReporter(reporterConfig);
reporter.initialize();
reporter.jasmineStarted({ totalSpecsDefined: 1 });
reporter.specStarted(specStatus);
reporter.specDone(specStatus);
reporter.jasmineDone({});
});
it("shows the disabled spec in the spec list", function() {
var specList = container.querySelector(".jasmine-summary");
expect(specList.innerHTML).toContain('with a disabled spec');
});
});
describe("when the specs are filtered", function() {
beforeEach(function() {
reporterConfig.filterSpecs = true;
reporter = new jasmineUnderTest.HtmlReporter(reporterConfig);
reporter.initialize();
reporter.jasmineStarted({ totalSpecsDefined: 1 });
reporter.specStarted(specStatus);
reporter.specDone(specStatus);
reporter.jasmineDone({});
});
it("doesn't show the disabled spec in the spec list", function() {
var specList = container.querySelector(".jasmine-summary");
expect(specList.innerHTML).toEqual('');
});
});
});
describe("and there are pending specs", function() {
var env, container, reporter;
beforeEach(function() {
env = new j$.Env();
env = new jasmineUnderTest.Env();
container = document.createElement("div");
var getContainer = function() { return container; };
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
@@ -820,10 +914,10 @@ describe("New HtmlReporter", function() {
var env, container, reporter;
beforeEach(function() {
env = new j$.Env();
env = new jasmineUnderTest.Env();
container = document.createElement("div");
var getContainer = function() { return container; }
reporter = new j$.HtmlReporter({
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },

View File

@@ -1,14 +1,14 @@
describe("j$.HtmlSpecFilter", function() {
describe("jasmineUnderTest.HtmlSpecFilter", function() {
it("should match when no string is provided", function() {
var specFilter = new j$.HtmlSpecFilter();
var specFilter = new jasmineUnderTest.HtmlSpecFilter();
expect(specFilter.matches("foo")).toBe(true);
expect(specFilter.matches("*bar")).toBe(true);
});
it("should only match the provided string", function() {
var specFilter = new j$.HtmlSpecFilter({
var specFilter = new jasmineUnderTest.HtmlSpecFilter({
filterString: function() { return "foo"; }
});

View File

@@ -2,7 +2,7 @@ describe("MatchersSpec - HTML Dependent", function () {
var env, spec;
beforeEach(function() {
env = new j$.Env();
env = new jasmineUnderTest.Env();
var suite = env.describe("suite", function() {
spec = env.it("spec", function() {

View File

@@ -1,15 +1,15 @@
describe("j$.pp (HTML Dependent)", function () {
describe("jasmineUnderTest.pp (HTML Dependent)", function () {
it("should stringify HTML nodes properly", function() {
var sampleNode = document.createElement('div');
sampleNode.innerHTML = 'foo<b>bar</b>';
expect(j$.pp(sampleNode)).toEqual("HTMLNode");
expect(j$.pp({foo: sampleNode})).toEqual("Object({ foo: HTMLNode })");
expect(jasmineUnderTest.pp(sampleNode)).toEqual("HTMLNode");
expect(jasmineUnderTest.pp({foo: sampleNode})).toEqual("Object({ foo: HTMLNode })");
});
it("should print Firefox's wrapped native objects correctly", function() {
if(jasmine.getEnv().firefoxVersion) {
try { new CustomEvent(); } catch(e) { var err = e; };
expect(j$.pp(err)).toMatch(/Not enough arguments/);
expect(jasmineUnderTest.pp(err)).toMatch(/Not enough arguments/);
}
});
});

View File

@@ -5,7 +5,7 @@ describe("QueryString", function() {
var windowLocation = {
search: ""
},
queryString = new j$.QueryString({
queryString = new jasmineUnderTest.QueryString({
getWindowLocation: function() { return windowLocation }
});
@@ -18,7 +18,7 @@ describe("QueryString", function() {
var windowLocation = {
search: "?foo=bar"
},
queryString = new j$.QueryString({
queryString = new jasmineUnderTest.QueryString({
getWindowLocation: function() { return windowLocation }
});
@@ -34,7 +34,7 @@ describe("QueryString", function() {
var windowLocation = {
search: "?foo=bar"
},
queryString = new j$.QueryString({
queryString = new jasmineUnderTest.QueryString({
getWindowLocation: function() { return windowLocation }
});
@@ -51,7 +51,7 @@ describe("QueryString", function() {
var windowLocation = {
search: "?baz=quux%20corge"
},
queryString = new j$.QueryString({
queryString = new jasmineUnderTest.QueryString({
getWindowLocation: function() { return windowLocation }
});
@@ -62,7 +62,7 @@ describe("QueryString", function() {
var windowLocation = {
search: ""
},
queryString = new j$.QueryString({
queryString = new jasmineUnderTest.QueryString({
getWindowLocation: function() { return windowLocation }
});

View File

@@ -4,7 +4,7 @@ describe("ResultsNode", function() {
id: 123,
message: "foo"
},
node = new j$.ResultsNode(fakeResult, "suite", null);
node = new jasmineUnderTest.ResultsNode(fakeResult, "suite", null);
expect(node.result).toBe(fakeResult);
expect(node.type).toEqual("suite");
@@ -19,7 +19,7 @@ describe("ResultsNode", function() {
id: 456,
message: "bar"
},
node = new j$.ResultsNode(fakeResult, "suite", null);
node = new jasmineUnderTest.ResultsNode(fakeResult, "suite", null);
node.addChild(fakeChildResult, "spec");
@@ -37,7 +37,7 @@ describe("ResultsNode", function() {
id: 456,
message: "bar"
},
node = new j$.ResultsNode(fakeResult, "suite", null);
node = new jasmineUnderTest.ResultsNode(fakeResult, "suite", null);
node.addChild(fakeChildResult, "spec");
@@ -53,7 +53,7 @@ describe("ResultsNode", function() {
id: 456,
message: "bar"
},
node = new j$.ResultsNode(fakeResult, "suite", null);
node = new jasmineUnderTest.ResultsNode(fakeResult, "suite", null);
node.addChild(fakeChildResult, "spec");

View File

@@ -2,6 +2,7 @@
use_sauce: <%= ENV['USE_SAUCE'] %>
browser: <%= ENV['JASMINE_BROWSER'] %>
sauce:
sauce_connect_path: <%= ENV['SAUCE_CONNECT_PATH'].inspect %>
name: jasmine-core <%= Time.now.to_s %>
username: <%= ENV['SAUCE_USERNAME'] %>
access_key: <%= ENV['SAUCE_ACCESS_KEY'] %>
@@ -11,6 +12,6 @@ sauce:
- CI
tunnel_identifier: <%= ENV['TRAVIS_JOB_NUMBER'] ? %Q("#{ENV['TRAVIS_JOB_NUMBER']}") : nil %>
os: <%= ENV['SAUCE_OS'] %>
browser_version: <%= ENV['SAUCE_BROWSER_VERSION'] %>
browser_version: "<%= ENV['SAUCE_BROWSER_VERSION'] %>"

View File

@@ -1,195 +0,0 @@
var fs = require('fs');
var util = require('util');
var path = require('path');
// boot code for jasmine
var jasmineRequire = require('../lib/jasmine-core/jasmine.js');
var jasmine = jasmineRequire.core(jasmineRequire);
var consoleFns = require('../lib/console/console.js');
extend(jasmineRequire, consoleFns);
jasmineRequire.console(jasmineRequire, jasmine);
var env = jasmine.getEnv();
var jasmineInterface = {
describe: function(description, specDefinitions) {
return env.describe(description, specDefinitions);
},
xdescribe: function(description, specDefinitions) {
return env.xdescribe(description, specDefinitions);
},
it: function(desc, func) {
return env.it(desc, func);
},
xit: function(desc, func) {
return env.xit(desc, func);
},
beforeEach: function(beforeEachFunction) {
return env.beforeEach(beforeEachFunction);
},
afterEach: function(afterEachFunction) {
return env.afterEach(afterEachFunction);
},
expect: function(actual) {
return env.expect(actual);
},
spyOn: function(obj, methodName) {
return env.spyOn(obj, methodName);
},
jsApiReporter: new jasmine.JsApiReporter({
timer: new jasmine.Timer()
}),
beforeAll: function(beforeAllFunction) {
return env.beforeAll(beforeAllFunction);
},
afterAll: function(afterAllFunction) {
return env.afterAll(afterAllFunction);
}
};
extend(global, jasmineInterface);
function extend(destination, source) {
for (var property in source) destination[property] = source[property];
return destination;
}
jasmine.addCustomEqualityTester = function(tester) {
env.addCustomEqualityTester(tester);
};
jasmine.addMatchers = function(matchers) {
return env.addMatchers(matchers);
};
jasmine.clock = function() {
return env.clock;
};
// Jasmine "runner"
function executeSpecs(specs, done, isVerbose, showColors) {
global.jasmine = jasmine;
for (var i = 0; i < specs.length; i++) {
var filename = specs[i];
require(filename.replace(/\.\w+$/, ""));
}
var env = jasmine.getEnv();
var consoleReporter = new jasmine.ConsoleReporter({
print: util.print,
onComplete: done,
showColors: showColors,
timer: new jasmine.Timer()
});
env.addReporter(consoleReporter);
env.execute();
}
function getFiles(dir, matcher) {
var allFiles = [];
if (fs.statSync(dir).isFile() && dir.match(matcher)) {
allFiles.push(dir);
} else {
var files = fs.readdirSync(dir);
for (var i = 0, len = files.length; i < len; ++i) {
var filename = dir + '/' + files[i];
if (fs.statSync(filename).isFile() && filename.match(matcher)) {
allFiles.push(filename);
} else if (fs.statSync(filename).isDirectory()) {
var subfiles = getFiles(filename);
subfiles.forEach(function(result) {
allFiles.push(result);
});
}
}
}
return allFiles;
}
function getSpecFiles(dir) {
return getFiles(dir, new RegExp("Spec.js$"));
}
var j$require = (function() {
var exported = {},
j$req;
global.getJasmineRequireObj = getJasmineRequireObj;
j$req = require(__dirname + "/../src/core/requireCore.js");
extend(j$req, require(__dirname + "/../src/console/requireConsole.js"));
var srcFiles = getFiles(__dirname + "/../src/core");
srcFiles.push(__dirname + "/../src/version.js");
srcFiles.push(__dirname + "/../src/console/ConsoleReporter.js");
for (var i = 0; i < srcFiles.length; i++) {
require(srcFiles[i]);
}
extend(j$req, exported);
delete global.getJasmineRequireObj;
return j$req;
function getJasmineRequireObj() {
return exported;
}
}());
j$ = j$require.core(j$require);
j$require.console(j$require, j$);
// options from command line
var isVerbose = false;
var showColors = true;
var perfSuite = false;
process.argv.forEach(function(arg) {
switch (arg) {
case '--color':
showColors = true;
break;
case '--noColor':
showColors = false;
break;
case '--verbose':
isVerbose = true;
break;
case '--perf':
perfSuite = true;
break;
}
});
specs = [];
if (perfSuite) {
specs = getFiles(__dirname + '/performance', new RegExp("test.js$"));
} else {
var consoleSpecs = getSpecFiles(__dirname + "/console"),
coreSpecs = getSpecFiles(__dirname + "/core"),
specs = consoleSpecs.concat(coreSpecs);
}
executeSpecs(specs, function(passed) {
if (passed) {
process.exit(0);
} else {
process.exit(1);
}
}, isVerbose, showColors);

View File

@@ -5,9 +5,9 @@ describe('npm package', function() {
beforeAll(function() {
var shell = require('shelljs'),
pack = shell.exec('npm pack', { silent: true });
pack = shell.exec('npm pack', { silent: true});
this.tarball = pack.output.split('\n')[0];
this.tarball = pack.stdout.split('\n')[0];
this.tmpDir = temp.mkdirSync(); // automatically deleted on exit
var untar = shell.exec('tar -xzf ' + this.tarball + ' -C ' + this.tmpDir, { silent: true });
@@ -42,7 +42,7 @@ describe('npm package', function() {
}
};
fs.unlink(this.tarball);
fs.unlinkSync(this.tarball);
});
it('has a root path', function() {

View File

@@ -30,7 +30,7 @@ describe('Printing a big object', function(){
it('takes a resonable amount of time', function(){
bigObject = generateObject(0);
expect(j$.pp(bigObject)).toMatch(/cycle/);
expect(jasmineUnderTest.pp(bigObject)).toMatch(/cycle/);
});
});

View File

@@ -6,6 +6,7 @@
"npmPackage/**/*.js"
],
"helpers": [
"helpers/checkForSet.js",
"helpers/nodeDefineJasmineUnderTest.js"
],
"random": true

View File

@@ -17,10 +17,12 @@ src_files:
stylesheets:
helpers:
- 'helpers/BrowserFlags.js'
- 'helpers/checkForSet.js'
- 'helpers/defineJasmineUnderTest.js'
spec_files:
- '**/*[Ss]pec.js'
- '!npmPackage/**/*'
spec_dir: spec
random: true
spec_helper: spec/support/jasmine_helper.rb

Some files were not shown because too many files have changed in this diff Show More