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

Commit

Permalink
Testing Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
amoshaviv committed Dec 3, 2013
1 parent 0ffe987 commit 7354e78
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 156 deletions.
6 changes: 3 additions & 3 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = function(grunt) {
}
},
concurrent: {
tasks: ['nodemon', 'watch', 'karma:unit'],
tasks: ['nodemon', 'watch'],
options: {
logConcurrentOutput: true
}
Expand Down Expand Up @@ -89,5 +89,5 @@ module.exports = function(grunt) {
grunt.registerTask('default', ['jshint', 'concurrent']);

//Test task.
grunt.registerTask('test', ['env:test', 'mochaTest']);
};
grunt.registerTask('test', ['env:test', 'mochaTest', 'karma:unit']);
};
80 changes: 14 additions & 66 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
<<<<<<< HEAD
"name": "mean",
"description": "MEAN - A Modern Stack: MongoDB, ExpressJS, AngularJS, NodeJS. (BONUS: Passport User Support).",
"version": "0.1.0",
Expand Down Expand Up @@ -32,6 +31,7 @@
"passport-github": "latest",
"passport-google-oauth": "latest",
"underscore": "latest",
"async": "latest",
"view-helpers": "latest",
"mean-logger": "latest",
"forever": "latest",
Expand All @@ -47,69 +47,17 @@
"grunt-contrib-jshint": "latest",
"grunt-nodemon": "latest",
"grunt-concurrent": "latest",
"grunt-mocha-test": "latest"
"grunt-mocha-test": "latest",
"karma-script-launcher": "~0.1.0",
"karma-chrome-launcher": "~0.1.0",
"karma-firefox-launcher": "~0.1.0",
"karma-html2js-preprocessor": "~0.1.0",
"karma-jasmine": "~0.1.3",
"karma-requirejs": "~0.1.0",
"karma-coffee-preprocessor": "~0.1.0",
"karma-phantomjs-launcher": "~0.1.0",
"karma": "~0.10.4",
"grunt-karma": "~0.6.2",
"karma-coverage": "~0.1.0"
}
=======
"name": "mean",
"description": "MEAN - A Modern Stack: MongoDB, ExpressJS, AngularJS, NodeJS. (BONUS: Passport User Support).",
"version": "0.1.0",
"private": false,
"author": "Amos Haviv",
"repository": {
"type": "git",
"url": "https://github.com/linnovate/mean.git"
},
"engines": {
"node": "0.10.x",
"npm": "1.2.x"
},
"scripts": {
"start": "node node_modules/grunt-cli/bin/grunt",
"test": "node node_modules/grunt-cli/bin/grunt test",
"postinstall": "bower install"
},
"dependencies": {
"express": "latest",
"jade": "latest",
"mongoose": "latest",
"connect-mongo": "latest",
"connect-flash": "latest",
"crypto": "latest",
"passport": "latest",
"passport-local": "latest",
"passport-facebook": "latest",
"passport-twitter": "latest",
"passport-github": "latest",
"passport-google-oauth": "latest",
"underscore": "latest",
"async": "latest",
"view-helpers": "latest",
"mean-logger": "latest",
"forever": "latest",
"bower": "latest",
"grunt": "latest",
"grunt-cli": "latest",
"grunt-env": "latest"
},
"devDependencies": {
"supertest": "latest",
"should": "latest",
"grunt-contrib-watch": "latest",
"grunt-contrib-jshint": "latest",
"grunt-nodemon": "latest",
"grunt-concurrent": "latest",
"grunt-mocha-test": "latest",
"karma-script-launcher": "~0.1.0",
"karma-chrome-launcher": "~0.1.0",
"karma-firefox-launcher": "~0.1.0",
"karma-html2js-preprocessor": "~0.1.0",
"karma-jasmine": "~0.1.3",
"karma-requirejs": "~0.1.0",
"karma-coffee-preprocessor": "~0.1.0",
"karma-phantomjs-launcher": "~0.1.0",
"karma": "~0.10.4",
"grunt-karma": "~0.6.2",
"karma-coverage": "~0.1.0"
}
>>>>>>> pr/126
}
}
175 changes: 88 additions & 87 deletions test/karma/unit/controllers/articles.spec.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
(function () {
(function() {
'use strict';

// Articles Controller Spec
// Articles Controller Spec
describe('MEAN controllers', function() {

describe('MEAN controllers', function () {

describe('ArticlesController', function () {
describe('ArticlesController', function() {

// The $resource service augments the response object with methods for updating and deleting the resource.
// If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
// the responses exactly. To solve the problem, we use a newly-defined toEqualData Jasmine matcher.
// When the toEqualData matcher compares two objects, it takes only object properties into
// account and ignores methods.
beforeEach(function () {
beforeEach(function() {
this.addMatchers({
toEqualData: function (expected) {
toEqualData: function(expected) {
return angular.equals(this.actual, expected);
}
});
Expand All @@ -33,7 +32,7 @@
// The injector ignores leading and trailing underscores here (i.e. _$httpBackend_).
// This allows us to inject a service but then attach it to a variable
// with the same name as the service.
beforeEach(inject(function ($controller, $rootScope, _$location_, _$routeParams_, _$httpBackend_) {
beforeEach(inject(function($controller, $rootScope, _$location_, _$routeParams_, _$httpBackend_) {

scope = $rootScope.$new();

Expand All @@ -50,93 +49,95 @@
}));

it('$scope.find() should create an array with at least one article object ' +
'fetched from XHR', function () {
'fetched from XHR', function() {

// test expected GET request
$httpBackend.expectGET('articles').respond([
{title: 'An Article about MEAN', content: 'MEAN rocks!'}
]);
// test expected GET request
$httpBackend.expectGET('articles').respond([{
title: 'An Article about MEAN',
content: 'MEAN rocks!'
}]);

// run controller
scope.find();
$httpBackend.flush();
// run controller
scope.find();
$httpBackend.flush();

// test scope value
expect(scope.articles).toEqualData([
{title: 'An Article about MEAN', content: 'MEAN rocks!'}
]);
// test scope value
expect(scope.articles).toEqualData([{
title: 'An Article about MEAN',
content: 'MEAN rocks!'
}]);

});
});

it('$scope.findOne() should create an array with one article object fetched ' +
'from XHR using a articleId URL parameter', function () {
// fixture URL parament
$routeParams.articleId = '525a8422f6d0f87f0e407a33';

// fixture response object
var testArticleData = function () {
return {
title: 'An Article about MEAN',
content: 'MEAN rocks!'
'from XHR using a articleId URL parameter', function() {
// fixture URL parament
$routeParams.articleId = '525a8422f6d0f87f0e407a33';

// fixture response object
var testArticleData = function() {
return {
title: 'An Article about MEAN',
content: 'MEAN rocks!'
};
};
};

// test expected GET request with response object
$httpBackend.expectGET(/articles\/([0-9a-fA-F]{24})$/).respond(testArticleData());
// test expected GET request with response object
$httpBackend.expectGET(/articles\/([0-9a-fA-F]{24})$/).respond(testArticleData());

// run controller
scope.findOne();
$httpBackend.flush();
// run controller
scope.findOne();
$httpBackend.flush();

// test scope value
expect(scope.article).toEqualData(testArticleData());
// test scope value
expect(scope.article).toEqualData(testArticleData());

});
});

it('$scope.create() with valid form data should send a POST request ' +
'with the form input values and then ' +
'locate to new object URL', function () {

// fixture expected POST data
var postArticleData = function () {
return {
title: 'An Article about MEAN',
content: 'MEAN rocks!'
'locate to new object URL', function() {

// fixture expected POST data
var postArticleData = function() {
return {
title: 'An Article about MEAN',
content: 'MEAN rocks!'
};
};
};

// fixture expected response data
var responseArticleData = function () {
return {
_id: '525cf20451979dea2c000001',
title: 'An Article about MEAN',
content: 'MEAN rocks!'
// fixture expected response data
var responseArticleData = function() {
return {
_id: '525cf20451979dea2c000001',
title: 'An Article about MEAN',
content: 'MEAN rocks!'
};
};
};

// fixture mock form input values
scope.title = 'An Article about MEAN';
scope.content = 'MEAN rocks!';
// fixture mock form input values
scope.title = 'An Article about MEAN';
scope.content = 'MEAN rocks!';

// test post request is sent
$httpBackend.expectPOST('articles', postArticleData()).respond(responseArticleData());
// test post request is sent
$httpBackend.expectPOST('articles', postArticleData()).respond(responseArticleData());

// Run controller
scope.create();
$httpBackend.flush();
// Run controller
scope.create();
$httpBackend.flush();

// test form input(s) are reset
expect(scope.title).toEqual('');
expect(scope.content).toEqual('');
// test form input(s) are reset
expect(scope.title).toEqual('');
expect(scope.content).toEqual('');

// test URL location to new object
expect($location.path()).toBe('/articles/' + responseArticleData()._id);
});
// test URL location to new object
expect($location.path()).toBe('/articles/' + responseArticleData()._id);
});

it('$scope.update() should update a valid article', inject(function (Articles) {
it('$scope.update() should update a valid article', inject(function(Articles) {

// fixture rideshare
var putArticleData = function () {
var putArticleData = function() {
return {
_id: '525a8422f6d0f87f0e407a33',
title: 'An Article about MEAN',
Expand Down Expand Up @@ -171,29 +172,29 @@
}));

it('$scope.remove() should send a DELETE request with a valid articleId' +
'and remove the article from the scope', inject(function (Articles) {
'and remove the article from the scope', inject(function(Articles) {

// fixture rideshare
var article = new Articles({
_id: '525a8422f6d0f87f0e407a33'
});
// fixture rideshare
var article = new Articles({
_id: '525a8422f6d0f87f0e407a33'
});

// mock rideshares in scope
scope.articles = [];
scope.articles.push(article);
// mock rideshares in scope
scope.articles = [];
scope.articles.push(article);

// test expected rideshare DELETE request
$httpBackend.expectDELETE(/articles\/([0-9a-fA-F]{24})$/).respond(204);
// test expected rideshare DELETE request
$httpBackend.expectDELETE(/articles\/([0-9a-fA-F]{24})$/).respond(204);

// run controller
scope.remove(article);
$httpBackend.flush();
// run controller
scope.remove(article);
$httpBackend.flush();

// test after successful delete URL location articles lis
//expect($location.path()).toBe('/articles');
expect(scope.articles.length).toBe(0);
// test after successful delete URL location articles lis
//expect($location.path()).toBe('/articles');
expect(scope.articles.length).toBe(0);

}));
}));

});

Expand Down

0 comments on commit 7354e78

Please sign in to comment.