-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from aitboudad/test
feat(#79): Add initial work for Unit tests
- Loading branch information
Showing
13 changed files
with
913 additions
and
201 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Error.stackTraceLimit = Infinity; | ||
|
||
require('core-js/client/shim'); | ||
require('reflect-metadata'); | ||
|
||
require('zone.js/dist/zone'); | ||
require('zone.js/dist/long-stack-trace-zone'); | ||
require('zone.js/dist/proxy'); | ||
require('zone.js/dist/sync-test'); | ||
require('zone.js/dist/jasmine-patch'); | ||
require('zone.js/dist/async-test'); | ||
require('zone.js/dist/fake-async-test'); | ||
|
||
var appContext = require.context('./../src', true, /\.spec\.ts/); | ||
appContext.keys().forEach(appContext); | ||
|
||
var testing = require('@angular/core/testing'); | ||
var browser = require('@angular/platform-browser-dynamic/testing'); | ||
|
||
testing.TestBed.initTestEnvironment(browser.BrowserDynamicTestingModule, browser.platformBrowserDynamicTesting()); |
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,16 @@ | ||
const webpack = require('webpack'); | ||
|
||
module.exports = { | ||
entry: "./src/index", | ||
resolve: { | ||
extensions: ['', '.ts', '.webpack.js', '.web.js', '.js'], | ||
}, | ||
devtool: 'source-map', | ||
module: { | ||
loaders: [ | ||
{ test: /\.ts$/, loaders: ['awesome-typescript-loader', 'angular2-template-loader'] }, | ||
{ test: /\.html$/, loader: 'raw' }, | ||
] | ||
}, | ||
plugins: [], | ||
}; |
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
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 |
---|---|---|
@@ -1,92 +1,87 @@ | ||
// Karma configuration | ||
// Generated on Sat Apr 16 2016 02:03:54 GMT+0530 (India Standard Time) | ||
var path = require('path'); | ||
|
||
module.exports = function(config) { | ||
config.set({ | ||
var webpackConfig = require('./.config/webpack.test'); | ||
|
||
var ENV = process.env.npm_lifecycle_event; | ||
var isTestWatch = ENV === 'test-watch'; | ||
|
||
module.exports = function (config) { | ||
var _config = { | ||
|
||
// 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: [ | ||
'test/**/*Spec.ts', | ||
'test/**/*Spec.js' | ||
{ pattern: './.config/karma-shim.js', watched: false } | ||
], | ||
|
||
|
||
// list of files to exclude | ||
exclude: [ | ||
], | ||
|
||
exclude: [], | ||
|
||
// preprocess matching files before serving them to the browser | ||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor | ||
preprocessors: { | ||
'**/*.ts': ['typescript'] | ||
'./.config/karma-shim.js': ['webpack', 'sourcemap'] | ||
}, | ||
|
||
typescriptPreprocessor: { | ||
// options passed to the typescript compiler | ||
options: { | ||
emitDecoratorMetadata: true, | ||
experimentalDecorators: true, | ||
target: "es5", | ||
declaration: false, | ||
module: "system", | ||
moduleResolution: "node", | ||
sourceMap: false, // (optional) Generates corresponding .map file. | ||
noImplicitAny: true, // (optional) Warn on expressions and declarations with an implied 'any' type. | ||
noResolve: true, // (optional) Skip resolution and preprocessing. | ||
removeComments: true, // (optional) Do not emit comments to output. | ||
concatenateOutput: false // (optional) Concatenate and emit output to single file. By default true if module option is omited, otherwise false. | ||
}, | ||
// transforming the filenames | ||
transformPath: function(path) { | ||
return path.replace(/\.ts$/, '.js'); | ||
} | ||
webpack: webpackConfig, | ||
|
||
webpackMiddleware: { | ||
// webpack-dev-middleware configuration | ||
// i. e. | ||
stats: 'errors-only' | ||
}, | ||
|
||
webpackServer: { | ||
noInfo: true // please don't spam the console when running in karma! | ||
}, | ||
|
||
// test results reporter to use | ||
// possible values: 'dots', 'progress' | ||
// possible values: 'dots', 'progress', 'mocha' | ||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter | ||
reporters: ['progress'], | ||
|
||
reporters: ["mocha"], | ||
|
||
// 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, | ||
|
||
autoWatch: false, | ||
|
||
// start these browsers | ||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher | ||
browsers: ['Chrome', 'Firefox', 'PhantomJS'], | ||
|
||
browsers: isTestWatch ? ['Chrome'] : ['PhantomJS'], | ||
|
||
// 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 | ||
}) | ||
} | ||
singleRun: true | ||
}; | ||
|
||
if (!isTestWatch) { | ||
_config.reporters.push("coverage"); | ||
|
||
_config.coverageReporter = { | ||
dir: 'coverage/', | ||
reporters: [{ | ||
type: 'json', | ||
dir: 'coverage', | ||
subdir: 'json', | ||
file: 'coverage-final.json' | ||
}] | ||
}; | ||
} | ||
|
||
config.set(_config); | ||
|
||
}; |
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,29 @@ | ||
import { TestBed, ComponentFixture } from '@angular/core/testing'; | ||
import { createGenericTestComponent } from '../test-utils'; | ||
|
||
import { Component } from '@angular/core'; | ||
|
||
import { FormlyForm } from './formly.form'; | ||
import { FormlyModule } from '../core'; | ||
import { FormlyConfig } from '../services/formly.config'; | ||
|
||
// tslint:disable-next-line | ||
const createTestComponent = (html: string) => | ||
createGenericTestComponent(html, TestComponent) as ComponentFixture<TestComponent>; | ||
|
||
describe('Formly Form Component', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({declarations: [TestComponent], imports: [FormlyModule.forRoot()]}); | ||
}); | ||
|
||
it('should initialize inputs with default values', () => { | ||
const formlyForm = new FormlyForm(new FormlyConfig()); | ||
|
||
expect(formlyForm.model).toEqual({}); | ||
expect(formlyForm.fields).toEqual([]); | ||
}); | ||
}); | ||
|
||
@Component({selector: 'formly-form-test', template: '', entryComponents: []}) | ||
class TestComponent { | ||
} |
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
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,8 @@ | ||
import { TestBed, ComponentFixture } from '@angular/core/testing'; | ||
|
||
export function createGenericTestComponent<T>(html: string, type: {new (...args: any[]): T}): ComponentFixture<T> { | ||
TestBed.overrideComponent(type, {set: {template: html}}); | ||
const fixture = TestBed.createComponent(type); | ||
fixture.detectChanges(); | ||
return fixture as ComponentFixture<T>; | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.