Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

Commit

Permalink
fix(jasmine): removing jasmine tests - never going to work
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Feb 22, 2016
1 parent fd3a8f2 commit c018650
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 63 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ before_script:
- npm prune
script:
- npm run ng-versions
- npm run test-jasmine-2
after_success:
- npm run coveralls
- npm run coverage-codacy
Expand Down
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ We love open source and use the bleeding edge technology stack.
* [Helpful failure messages](#helpful-failure-messages)
* [Development](#development)
* [Updating dependencies](#updating-dependencies)
* [Note to Jasmine users](#note-to-jasmine-users)
* [Modules used](#modules-used)
* [License](#license)

Expand Down Expand Up @@ -519,7 +520,7 @@ example that tests Angular without a browser, only a synthetic emulation.

## Examples

Some examples use Jasmine matchers, others use `la` assertion from
Most examples use use the `la` assertion from the
[lazy-ass](https://github.com/bahmutov/lazy-ass) library and *done* callback argument
from [Mocha](http://visionmedia.github.io/mocha/) testing framework.

Expand Down Expand Up @@ -560,7 +561,7 @@ ngDescribe({
tests: function (deps) {
// deps object has every injected dependency as a property
it('has correct value foo', function () {
expect(deps.foo).toEqual('bar');
la(deps.foo === 'bar');
});
}
});
Expand Down Expand Up @@ -602,11 +603,11 @@ ngDescribe({
inject: 'addFoo',
tests: function (deps) {
it('is a function', function () {
expect(typeof deps.addFoo).toEqual('function');
la(typeof deps.addFoo === 'function');
});
it('appends value of foo to any string', function () {
var result = deps.addFoo('x');
expect(result).toEqual('xbar');
la(result === 'xbar');
});
}
});
Expand Down Expand Up @@ -1423,6 +1424,17 @@ If you use [npm-quick-run](https://github.com/bahmutov/npm-quick-run) you can us
nr u -m jscs


## Note to Jasmine users

We got very tired of fighting bugs in the [Jasmine](http://jasmine.github.io/) test framework.
From the broken order of `afterEach` callbacks to the `afterAll` not firing at all - the work arounds
we had to write quickly becamse insane. Thus we
[recommend Mocha](https://glebbahmutov.com/blog/picking-javascript-testing-framework/) testing
framework - fast, simple and seems to not suffer from any bugs. You do need your own assertion
framework, we use [lazy-ass](https://github.com/bahmutov/lazy-ass) and a library
of predicates [check-more-types](https://github.com/kensho/check-more-types).



## Modules used
* [check-more-types](https://github.com/kensho/check-more-types) - Large collection of predicates.
Expand Down
26 changes: 1 addition & 25 deletions dist/ng-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -3510,15 +3510,6 @@ if (String(/a/mig) !== '/a/gim') {
};
}

// collect afterEach callbacks from inside the unit test
// to work around Jasmine bug
// https://github.com/kensho/ng-describe/issues/74
var afters = [];
var _afterEach = window.afterEach;
window.afterEach = function saveAfterEach(cb) {
afters.push(cb);
};

var toExpose = options.exposeApi ? exposeApi() : undefined;

// call the user-supplied test function to register the actual unit tests
Expand Down Expand Up @@ -3583,33 +3574,18 @@ if (String(/a/mig) !== '/a/gim') {
}
cleanupCallbacks.push(deleteDependencies);

// run all callbacks after each unit test as a single function
function cleanUp(callbacks) {
la(check.array(callbacks), 'expected list of callbacks', callbacks);
log('inside cleanup afterEach', callbacks.length, 'callbacks');

callbacks.forEach(function (fn) {
la(check.fn(fn), 'expected function to cleanup, got', fn);
window.afterEach(fn);
bdd.afterEach(fn);
});
}

log('cleanupCallbacks', cleanupCallbacks.length);
cleanUp(cleanupCallbacks);

// restore the original afterEach
window.afterEach = _afterEach;

function singleAfterEachInOrder(afterCallbacks) {
la(check.array(afterCallbacks), 'expected array of callbacks', afterCallbacks);
log('single "after" block with', afterCallbacks.length, 'callbacks');
afterCallbacks.forEach(function (fn, k) {
log('"after callback"', k, fn.name);
fn();
});
}
var singleCleanup = singleAfterEachInOrder.bind(null, afters);
window.afterEach(singleCleanup);
}

bdd.describe(options.name, ngSpecs);
Expand Down
1 change: 1 addition & 0 deletions docs/README.tmpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{%= _.doc("./docs/api.md") %}
{%= _.doc("./docs/examples.md") %}
{%= _.doc("./docs/development.md") %}
{%= _.doc("./docs/jasmine.md") %}

## Modules used
{%= _.doc("./docs/modules-used.md") %}
Expand Down
8 changes: 4 additions & 4 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Examples

Some examples use Jasmine matchers, others use `la` assertion from
Most examples use use the `la` assertion from the
[lazy-ass](https://github.com/bahmutov/lazy-ass) library and *done* callback argument
from [Mocha](http://visionmedia.github.io/mocha/) testing framework.

Expand Down Expand Up @@ -41,7 +41,7 @@ ngDescribe({
tests: function (deps) {
// deps object has every injected dependency as a property
it('has correct value foo', function () {
expect(deps.foo).toEqual('bar');
la(deps.foo === 'bar');
});
}
});
Expand Down Expand Up @@ -83,11 +83,11 @@ ngDescribe({
inject: 'addFoo',
tests: function (deps) {
it('is a function', function () {
expect(typeof deps.addFoo).toEqual('function');
la(typeof deps.addFoo === 'function');
});
it('appends value of foo to any string', function () {
var result = deps.addFoo('x');
expect(result).toEqual('xbar');
la(result === 'xbar');
});
}
});
Expand Down
9 changes: 9 additions & 0 deletions docs/jasmine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Note to Jasmine users

We got very tired of fighting bugs in the [Jasmine](http://jasmine.github.io/) test framework.
From the broken order of `afterEach` callbacks to the `afterAll` not firing at all - the work arounds
we had to write quickly becamse insane. Thus we
[recommend Mocha](https://glebbahmutov.com/blog/picking-javascript-testing-framework/) testing
framework - fast, simple and seems to not suffer from any bugs. You do need your own assertion
framework, we use [lazy-ass](https://github.com/bahmutov/lazy-ass) and a library
of predicates [check-more-types](https://github.com/kensho/check-more-types).
1 change: 1 addition & 0 deletions docs/toc.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
* [Helpful failure messages](#helpful-failure-messages)
* [Development](#development)
* [Updating dependencies](#updating-dependencies)
* [Note to Jasmine users](#note-to-jasmine-users)
* [Modules used](#modules-used)
* [License](#license)
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@
"synthetic-browser": "mocha misc/*-spec.js",
"test": "npm run build",
"test-dependents": "dont-break",
"test-jasmine-2": "cd test/jasmine-2; npm install; npm test",
"test-ng-1.2": "cd test/angular-1.2; npm install; npm test",
"test-ng-1.3": "cd test/angular-1.3; npm install; npm test",
"test-ng-1.4": "cd test/angular-1.4; npm install; npm test",
Expand Down
26 changes: 1 addition & 25 deletions src/ng-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,15 +504,6 @@
};
}

// collect afterEach callbacks from inside the unit test
// to work around Jasmine bug
// https://github.com/kensho/ng-describe/issues/74
var afters = [];
var _afterEach = window.afterEach;
window.afterEach = function saveAfterEach(cb) {
afters.push(cb);
};

var toExpose = options.exposeApi ? exposeApi() : undefined;

// call the user-supplied test function to register the actual unit tests
Expand Down Expand Up @@ -577,33 +568,18 @@
}
cleanupCallbacks.push(deleteDependencies);

// run all callbacks after each unit test as a single function
function cleanUp(callbacks) {
la(check.array(callbacks), 'expected list of callbacks', callbacks);
log('inside cleanup afterEach', callbacks.length, 'callbacks');

callbacks.forEach(function (fn) {
la(check.fn(fn), 'expected function to cleanup, got', fn);
window.afterEach(fn);
bdd.afterEach(fn);
});
}

log('cleanupCallbacks', cleanupCallbacks.length);
cleanUp(cleanupCallbacks);

// restore the original afterEach
window.afterEach = _afterEach;

function singleAfterEachInOrder(afterCallbacks) {
la(check.array(afterCallbacks), 'expected array of callbacks', afterCallbacks);
log('single "after" block with', afterCallbacks.length, 'callbacks');
afterCallbacks.forEach(function (fn, k) {
log('"after callback"', k, fn.name);
fn();
});
}
var singleCleanup = singleAfterEachInOrder.bind(null, afters);
window.afterEach(singleCleanup);
}

bdd.describe(options.name, ngSpecs);
Expand Down
2 changes: 1 addition & 1 deletion test/after-each-context-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ angular.module('BeforeAndAfterA', [])
.value('foo', 'bar');

ngDescribe({
name: 'before and after example',
name: 'before and after each example',
module: 'BeforeAndAfterA',
inject: 'foo',
only: false,
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine-2/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function(config) {
files: [
'./angular-1.4/node_modules/angular/angular.js',
'./angular-1.4/node_modules/angular-mocks/angular-mocks.js',
'../lib/sinon.js',
// '../lib/sinon.js',
'../dist/ng-describe.js',
'../node_modules/lazy-ass-helpful/lazy-ass-helpful-browser.js',
'../node_modules/lazy-ass-helpful/lazy-ass-helpful-bdd.js',
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine-2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
"grunt-karma": "0.9.0",
"jasmine-core": "2.3.4",
"jasmine-core": "2.4.0",
"karma": "0.12.28",
"karma-chrome-launcher": "0.1.6",
"karma-jasmine": "0.3.6",
Expand Down

0 comments on commit c018650

Please sign in to comment.