-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests): Add ngrx test infrastructure
- Loading branch information
1 parent
f067cdb
commit a583221
Showing
8 changed files
with
239 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
var path = require('path'); | ||
|
||
module.exports = function(karma) { | ||
'use strict'; | ||
|
||
karma.set({ | ||
basePath: __dirname, | ||
|
||
frameworks: ['jasmine'], | ||
|
||
files: [ | ||
{ pattern: 'tests.js', watched: false } | ||
], | ||
|
||
exclude: [], | ||
|
||
preprocessors: { | ||
'tests.js': ['coverage', 'webpack', 'sourcemap'] | ||
}, | ||
|
||
reporters: ['mocha', 'coverage'], | ||
|
||
coverageReporter: { | ||
dir: 'coverage/', | ||
subdir: '.', | ||
reporters: [ | ||
{ type: 'text-summary' }, | ||
{ type: 'json' }, | ||
{ type: 'html' } | ||
] | ||
}, | ||
|
||
browsers: ['Chrome'], | ||
|
||
port: 9018, | ||
runnerPort: 9101, | ||
colors: true, | ||
logLevel: karma.LOG_INFO, | ||
autoWatch: true, | ||
singleRun: false, | ||
|
||
webpack: { | ||
devtool: 'inline-source-map', | ||
resolve: { | ||
root: __dirname, | ||
extensions: ['', '.ts', '.js'] | ||
}, | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.ts?$/, | ||
exclude: /(node_modules)/, | ||
loader: 'awesome-typescript-loader' | ||
} | ||
], | ||
postLoaders: [ | ||
{ | ||
test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader', | ||
include: path.resolve(__dirname, 'lib'), | ||
exclude: [ | ||
/\.(e2e|spec)\.ts$/, | ||
/node_modules/ | ||
] | ||
} | ||
] | ||
}, | ||
ts: { | ||
configFileName: './spec/tsconfig.json' | ||
} | ||
}, | ||
|
||
webpackServer: { | ||
noInfo: true | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Book } from '../../src/models/book'; | ||
|
||
|
||
export const TestBook: Book = { | ||
id: '123', | ||
volumeInfo: { | ||
title: 'This is a test book', | ||
subtitle: 'Not a real book', | ||
authors: [ 'Mike Ryan' ], | ||
publisher: 'ngrx', | ||
publishDate: '06082016', | ||
description: 'This book is used for mocks in tests', | ||
averageRating: 3, | ||
ratingsCount: 10, | ||
imageLinks: { | ||
thumbnail: '/path/to/an/image.jpg', | ||
smallThumbnail: '/path/to/a/smaller/image.png' | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import 'rxjs/add/operator/let'; | ||
import { of } from 'rxjs/observable/of'; | ||
import { BookActions } from '../../src/actions/book'; | ||
import booksReducer, * as fromBooks from '../../src/reducers/books'; | ||
import { TestBook } from '../fixtures/books'; | ||
|
||
describe('Books', function() { | ||
const bookActions = new BookActions(); | ||
|
||
describe('Reducer', function() { | ||
it('should have an empty initial state', function() { | ||
const initialState = booksReducer(undefined, { type: 'test-action' }); | ||
|
||
expect(initialState.ids).toEqual([]); | ||
expect(initialState.entities).toEqual({}); | ||
}); | ||
|
||
it('should add a book to the entities table and its ID to the IDs list when loaded', function() { | ||
const action = bookActions.loadBook(TestBook); | ||
const state = booksReducer(undefined, action); | ||
|
||
expect(state.ids).toEqual([ TestBook.id ]); | ||
expect(state.entities[TestBook.id]).toBe(TestBook); | ||
}); | ||
}); | ||
|
||
describe('Selectors', function() { | ||
describe('getBookEntities', function() { | ||
it('should get the entities table out of the books state', function() { | ||
const state = booksReducer(undefined, { type: 'test-action' }); | ||
|
||
of(state).let(fromBooks.getBookEntities()).subscribe(entities => { | ||
expect(entities).toBe(state.entities); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getBook', function() { | ||
it('should get a selected book out of the books state', function() { | ||
const state: fromBooks.BooksState = { | ||
entities: { | ||
[TestBook.id]: TestBook | ||
}, | ||
ids: [ TestBook.id ] | ||
}; | ||
|
||
of(state).let(fromBooks.getBook(TestBook.id)).subscribe(book => { | ||
expect(book).toBe(TestBook); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getBooks', function() { | ||
it('should return all of the books in an array for a given list of ids', function() { | ||
const state: fromBooks.BooksState = { | ||
entities: { | ||
[TestBook.id]: TestBook | ||
}, | ||
ids: [ TestBook.id ] | ||
}; | ||
|
||
of(state).let(fromBooks.getBooks([ TestBook.id ])).subscribe(books => { | ||
expect(books).toEqual([ TestBook ]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require('core-js'); | ||
require('ts-helpers'); | ||
require('zone.js/dist/zone.js'); | ||
require('zone.js/dist/long-stack-trace-zone.js'); | ||
require('zone.js/dist/jasmine-patch.js'); | ||
require('zone.js/dist/async-test.js'); | ||
require('zone.js/dist/fake-async-test.js'); | ||
|
||
Error.stackTraceLimit = Infinity; | ||
|
||
require('reflect-metadata'); | ||
|
||
const testContext = require.context('./spec', true, /\.spec\.ts/); | ||
testContext.keys().forEach(testContext); | ||
|
||
const testing = require('@angular/core/testing'); | ||
const browser = require('@angular/platform-browser-dynamic/testing'); | ||
testing.setBaseTestProviders( | ||
browser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, | ||
browser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters