11 changed files with 1742 additions and 0 deletions
Split View
Diff Options
-
1scotch-angular-testing/.gitignore
-
13scotch-angular-testing/README.md
-
0scotch-angular-testing/app/app.css
-
10scotch-angular-testing/app/app.js
-
33scotch-angular-testing/app/index.html
-
50scotch-angular-testing/app/services/users/users.js
-
74scotch-angular-testing/app/services/users/users.spec.js
-
74scotch-angular-testing/karma.conf.js
-
1433scotch-angular-testing/package-lock.json
-
28scotch-angular-testing/package.json
-
26scotch-angular-testing/server.js
@ -0,0 +1 @@ |
|||
/node_modules |
|||
@ -0,0 +1,13 @@ |
|||
### Setup |
|||
|
|||
`nvm use 5.0` |
|||
|
|||
`npm install` |
|||
|
|||
`node server.js` |
|||
|
|||
### Test |
|||
|
|||
`npm install -g karma-cli` |
|||
|
|||
`karma start` |
|||
@ -0,0 +1,10 @@ |
|||
(function() { |
|||
'use strict'; |
|||
|
|||
angular.module('meetIrl', [ |
|||
'ui.router' |
|||
]) |
|||
.config(function($urlRouterProvider) { |
|||
$urlRouterProvider.otherwise("/"); |
|||
}); |
|||
})(); |
|||
@ -0,0 +1,33 @@ |
|||
<!doctype html> |
|||
|
|||
<html lang="en"> |
|||
<head> |
|||
<meta charset="utf-8"> |
|||
<meta name="description" content=""> |
|||
<meta name="author" content=""> |
|||
|
|||
<base href="/"> |
|||
|
|||
<title>MeetIrl</title> |
|||
|
|||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> |
|||
<link rel="stylesheet" href="app.css"> |
|||
|
|||
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script> |
|||
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.18/angular-ui-router.js"></script> |
|||
|
|||
<script src="app.js"></script> |
|||
</head> |
|||
|
|||
<body ng-app="meetIrl"> |
|||
<nav class="navbar navbar-default"> |
|||
<div class="container"> |
|||
<div class="navbar-header"> |
|||
<a class="navbar-brand">MeetIrl</a> |
|||
</div> |
|||
</div> |
|||
</nav> |
|||
|
|||
<div ui-view>Hello, world!</div> |
|||
</body> |
|||
</html> |
|||
@ -0,0 +1,50 @@ |
|||
(function() { |
|||
'use strict'; |
|||
|
|||
angular.module('api.users', []) |
|||
.factory('Users', function() { |
|||
var Users = {}; |
|||
var userList = [ |
|||
{ |
|||
id: '1', |
|||
name: 'Jane', |
|||
role: 'Designer', |
|||
location: 'New York', |
|||
twitter: 'gijane' |
|||
}, |
|||
{ |
|||
id: '2', |
|||
name: 'Bob', |
|||
role: 'Developer', |
|||
location: 'New York', |
|||
twitter: 'billybob' |
|||
}, |
|||
{ |
|||
id: '3', |
|||
name: 'Jim', |
|||
role: 'Developer', |
|||
location: 'Chicago', |
|||
twitter: 'jimbo' |
|||
}, |
|||
{ |
|||
id: '4', |
|||
name: 'Bill', |
|||
role: 'Designer', |
|||
location: 'LA', |
|||
twitter: 'dabill' |
|||
} |
|||
]; |
|||
|
|||
Users.all = function() { |
|||
return userList; |
|||
}; |
|||
|
|||
Users.findById = function(id) { |
|||
return userList.find(function(user) { |
|||
return user.id === id; |
|||
}); |
|||
}; |
|||
|
|||
return Users; |
|||
}); |
|||
})(); |
|||
@ -0,0 +1,74 @@ |
|||
describe('Users factory', function() { |
|||
var Users; |
|||
var userList = [ |
|||
{ |
|||
id: '1', |
|||
name: 'Jane', |
|||
role: 'Designer', |
|||
location: 'New York', |
|||
twitter: 'gijane' |
|||
}, |
|||
{ |
|||
id: '2', |
|||
name: 'Bob', |
|||
role: 'Developer', |
|||
location: 'New York', |
|||
twitter: 'billybob' |
|||
}, |
|||
{ |
|||
id: '3', |
|||
name: 'Jim', |
|||
role: 'Developer', |
|||
location: 'Chicago', |
|||
twitter: 'jimbo' |
|||
}, |
|||
{ |
|||
id: '4', |
|||
name: 'Bill', |
|||
role: 'Designer', |
|||
location: 'LA', |
|||
twitter: 'dabill' |
|||
} |
|||
]; |
|||
var singleUser = { |
|||
id: '2', |
|||
name: 'Bob', |
|||
role: 'Developer', |
|||
location: 'New York', |
|||
twitter: 'billybob' |
|||
}; |
|||
|
|||
beforeEach(angular.mock.module('api.users')); |
|||
|
|||
beforeEach(inject(function(_Users_) { |
|||
Users = _Users_; |
|||
})); |
|||
|
|||
it('should exist', function() { |
|||
expect(Users).toBeDefined(); |
|||
}); |
|||
|
|||
describe('.all()', function() { |
|||
it('should exist', function() { |
|||
expect(Users.all).toBeDefined(); |
|||
}); |
|||
|
|||
it('should return a hard-coded list of users', function() { |
|||
expect(Users.all()).toEqual(userList); |
|||
}); |
|||
}); |
|||
|
|||
describe('.findById()', function() { |
|||
it('should exist', function() { |
|||
expect(Users.findById).toBeDefined(); |
|||
}); |
|||
|
|||
it('should return one user object if it exists', function() { |
|||
expect(Users.findById('2')).toEqual(singleUser); |
|||
}); |
|||
|
|||
it('should return undefined if the user cannot be found', function() { |
|||
expect(Users.findById('ABC')).not.toBeDefined(); |
|||
}); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,74 @@ |
|||
// Karma configuration
|
|||
// Generated on Wed Jun 01 2016 17:37:40 GMT-0400 (EDT)
|
|||
|
|||
module.exports = function(config) { |
|||
config.set({ |
|||
|
|||
// base path that will be used to resolve all patterns (eg. files, exclude)
|
|||
basePath: '', |
|||
|
|||
|
|||
// frameworks to use
|
|||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
|||
frameworks: ['jasmine'], |
|||
|
|||
|
|||
// list of files / patterns to load in the browser
|
|||
files: [ |
|||
'./node_modules/angular/angular.js', |
|||
'./node_modules/angular-ui-router/release/angular-ui-router.js', |
|||
'./node_modules/angular-mocks/angular-mocks.js', |
|||
'./app/services/users/users.js', |
|||
'./app/app.js', |
|||
'./app/services/users/users.spec.js' |
|||
], |
|||
|
|||
|
|||
// list of files to exclude
|
|||
exclude: [ |
|||
], |
|||
|
|||
|
|||
// preprocess matching files before serving them to the browser
|
|||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
|||
preprocessors: { |
|||
}, |
|||
|
|||
|
|||
// test results reporter to use
|
|||
// possible values: 'dots', 'progress'
|
|||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
|||
reporters: ['spec'], |
|||
|
|||
|
|||
// web server port
|
|||
port: 9876, |
|||
|
|||
|
|||
// enable / disable colors in the output (reporters and logs)
|
|||
colors: true, |
|||
|
|||
|
|||
// level of logging
|
|||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
|||
logLevel: config.LOG_INFO, |
|||
|
|||
|
|||
// enable / disable watching file and executing tests whenever any file changes
|
|||
autoWatch: true, |
|||
|
|||
|
|||
// start these browsers
|
|||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
|||
browsers: ['Chrome'], |
|||
|
|||
|
|||
// Continuous Integration mode
|
|||
// if true, Karma captures browsers, runs the tests and exits
|
|||
singleRun: false, |
|||
|
|||
// Concurrency level
|
|||
// how many browser should be started simultaneous
|
|||
concurrency: Infinity |
|||
}) |
|||
} |
|||
1433
scotch-angular-testing/package-lock.json
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,28 @@ |
|||
{ |
|||
"name": "scotch-angular-testing", |
|||
"version": "1.0.0", |
|||
"description": "Learn to test Angular code with Jasmine and Karma", |
|||
"main": "server.js", |
|||
"scripts": { |
|||
"test": "karma start", |
|||
"start": "node server.js" |
|||
}, |
|||
"author": "Adam Morgan", |
|||
"license": "ISC", |
|||
"dependencies": { |
|||
"body-parser": "^1.15.1", |
|||
"express": "^4.13.4", |
|||
"morgan": "^1.7.0", |
|||
"path": "^0.12.7" |
|||
}, |
|||
"devDependencies": { |
|||
"angular": "^1.8.1", |
|||
"angular-mocks": "^1.8.1", |
|||
"angular-ui-router": "^1.0.8", |
|||
"jasmine": "^3.6.2", |
|||
"karma": "^4.0.1", |
|||
"karma-chrome-launcher": "^3.1.0", |
|||
"karma-jasmine": "^4.0.1", |
|||
"karma-spec-reporter": "0.0.26" |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
var express = require('express'), |
|||
app = express(), |
|||
bodyParser = require('body-parser'), |
|||
morgan = require('morgan'), |
|||
path = require('path'); |
|||
|
|||
app.use(bodyParser.urlencoded({ extended: true })); |
|||
app.use(bodyParser.json()); |
|||
|
|||
app.use(function(req, res, next) { |
|||
res.setHeader('Access-Control-Allow-Origin', '*'); |
|||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST'); |
|||
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With, content-type, Authorization'); |
|||
next(); |
|||
}); |
|||
|
|||
app.use(morgan('dev')); |
|||
|
|||
app.use(express.static(__dirname + '/app')); |
|||
|
|||
app.get('*', function(req, res) { |
|||
res.sendFile(path.join(__dirname + '/index.html')); |
|||
}); |
|||
|
|||
app.listen(8080); |
|||
console.log('meet-irl is running on 8080'); |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue