Skip to content

Commit

Permalink
chore(tests): updates jasmine version
Browse files Browse the repository at this point in the history
  • Loading branch information
iobaixas committed Nov 26, 2014
1 parent e71cd36 commit 5fcdfe6
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"karma-chrome-launcher": "*",
"karma-cli": "*",
"karma-firefox-launcher": "*",
"karma-jasmine": "*",
"karma-jasmine": "~0.2",
"karma-osx-reporter": "*",
"karma-requirejs": "*",
"karma-sauce-launcher": "^0.2.10",
Expand Down
2 changes: 1 addition & 1 deletion test/collection-api-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ describe('Restmod collection:', function() {
describe('$unwrap', function() {

it('should call the type\'s unpack method', function() {
spyOn(Bike, 'unpack').andReturn([]);
spyOn(Bike, 'unpack').and.returnValue([]);
var bikes = Bike.$collection();

var raw = [{}];
Expand Down
6 changes: 3 additions & 3 deletions test/extended-api-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ describe('Restmod collection:', function() {
describe('$resolve', function() {
it('should skip $fetch if already resolved', function() {
var bike = Bike.$new(1);
spyOn(bike, '$fetch').andCallThrough();
spyOn(bike, '$fetch').and.callThrough();

bike.$decode({ name: 'nomad' }).$resolve();
expect(bike.$fetch).not.toHaveBeenCalled();
});

it('should trigger a call to $fetch if not resolved', function() {
var bike = Bike.$new(1);
spyOn(bike, '$fetch').andCallThrough();
spyOn(bike, '$fetch').and.callThrough();

bike.$resolve();
expect(bike.$fetch).toHaveBeenCalled();
});

it('should trigger a call to $fetch if reset', function() {
var bike = Bike.$new(1);
spyOn(bike, '$fetch').andCallThrough();
spyOn(bike, '$fetch').and.callThrough();

bike.$decode({ name: 'nomad' }).$reset().$resolve();
expect(bike.$fetch).toHaveBeenCalled();
Expand Down
25 changes: 25 additions & 0 deletions test/model-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ describe('Restmod model class:', function() {
query = Bike.$collection();
}));

describe('equality', function() {

// record equality test, I'll keep this here just in case a restmod-jasmine adaptor is built

var recordEquality = function(_first, _second) {
if (typeof _first === 'object' && typeof _second === 'object' &&
_first && _second && _first.$type === _second.$type) {
for(var key in _first) {
if(_first.hasOwnProperty(key) && key[0] !== '$') {
if(!jasmine.matchersUtil.equals(_first[key], _second[key], [])) { return false; }
}
}
return true;
}
};

beforeEach(function() {
jasmine.addCustomEqualityTester(recordEquality);
});

it('should work for instances that are equal', function() {
expect(Bike.$build({ model: 'slash' })).toEqual(Bike.$build({ model: 'slash' }));
});
});

describe('constructor', function() {

it('should fire the after-init hook', function() {
Expand Down
4 changes: 2 additions & 2 deletions test/plugins/find-many-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ describe('Plugin: Find Many plugin', function() {

it('should call $decode only once in shared instances', function() {
var bike = Bike.$new(1);
spyOn(bike, '$decode').andCallThrough();
spyOn(bike, '$decode').and.callThrough();

Bike.$populate([ bike, bike ]);
$httpBackend.expectGET('/api/bikes?ids=1').respond(200, [ { id: 1, brand: 'Giant' } ]);
$httpBackend.flush();

expect(bike.$decode.callCount).toEqual(1);
expect(bike.$decode.calls.count()).toEqual(1);
});

});
Expand Down
16 changes: 8 additions & 8 deletions test/plugins/preload-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ describe('Plugin: Preload function', function() {
});

it('should call populate on preloaded resource ', function() {
User.$populate = jasmine.createSpy().andReturn(User.dummy(true));
User.$populate = jasmine.createSpy().and.returnValue(User.dummy(true));

bikes.$preload('user');
expect(User.$populate).toHaveBeenCalledWith([
jasmine.objectContaining({ $pk: 10 }),
jasmine.objectContaining({ $pk: 11 }),
jasmine.objectContaining({ $pk: 13 })
], undefined);
expect(User.$populate.callCount).toEqual(1);
expect(User.$populate.calls.count()).toEqual(1);
});

it('should support parameters', function() {
User.$populate = jasmine.createSpy().andReturn(User.dummy(true));
User.$populate = jasmine.createSpy().and.returnValue(User.dummy(true));

bikes.$preload({ path: 'user', params: { include: 'all' } });
expect(User.$populate).toHaveBeenCalledWith([
Expand All @@ -62,7 +62,7 @@ describe('Plugin: Preload function', function() {

it('should work on single records too', function() {
var bike = Bike.$new(1).$decode({ userId: 10, brand: 'Santa Cruz' });
User.$populate = jasmine.createSpy().andReturn(User.dummy(true));
User.$populate = jasmine.createSpy().and.returnValue(User.dummy(true));

bike.$preload('user');
expect(User.$populate).toHaveBeenCalledWith(
Expand All @@ -72,24 +72,24 @@ describe('Plugin: Preload function', function() {
});

it('should properly manager hierachies', function() {
User.$populate = jasmine.createSpy().andCallFake(function(_records) {
User.$populate = jasmine.createSpy().and.callFake(function(_records) {
_records[0].$decode({ rideIds: [1], friendIds: [1] });
_records[1].$decode({ rideIds: [5], friendIds: [] });
_records[2].$decode({ rideIds: [5], friendIds: [2, 3] });
return User.dummy(true);
});

Ride.$populate = jasmine.createSpy().andReturn(User.dummy(true));
Ride.$populate = jasmine.createSpy().and.returnValue(User.dummy(true));

bikes.$preload('user.friends', 'user.rides');
expect(Ride.$populate.callCount).toEqual(1);
expect(Ride.$populate.calls.count()).toEqual(1);
expect(Ride.$populate).toHaveBeenCalledWith([
jasmine.objectContaining({ $pk: 1 }),
jasmine.objectContaining({ $pk: 5 }),
jasmine.objectContaining({ $pk: 5 })
], undefined);

expect(User.$populate.callCount).toEqual(2);
expect(User.$populate.calls.count()).toEqual(2);
expect(User.$populate).toHaveBeenCalledWith([
jasmine.objectContaining({ $pk: 1 }),
jasmine.objectContaining({ $pk: 2 }),
Expand Down

0 comments on commit 5fcdfe6

Please sign in to comment.