Last active
February 25, 2021 08:51
-
-
Save linuxsimba/27324f7c3c5c267f124e703a9990f446 to your computer and use it in GitHub Desktop.
NG10/NG7 unit testing component unit test example
This file contains hidden or 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
import { Component } from '@angular/core'; | |
import { TestBed } from '@angular/core/testing'; | |
import { customNsTestBedAfterEach, customNsTestBedBeforeEach } from './setup'; | |
@Component({ | |
selector: 'test-comp', | |
template: '' // template is blank, because code does not have NO_ERRORS_SCHEMA and also we don't care. only testing functions in component | |
}) | |
class TestComponent{ | |
hello(): string { return 'hello'; } | |
} | |
let component: TestComponent; | |
describe('Test Component', () => { | |
beforeEach(customNsTestBedBeforeEach( | |
[], | |
[ TestComponent ], | |
[] | |
)); | |
afterEach(() => customNsTestBedAfterEach()); | |
describe('Function Tests -', () => { | |
beforeEach(() => { | |
component = TestBed.inject(TestComponent); | |
}); | |
describe('hello()', () => { | |
it('should say "hello"', () => { | |
expect(component.hello()).toEqual('hello'); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment