-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnew-book.component.spec.ts
47 lines (41 loc) · 1.59 KB
/
new-book.component.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { getStoreServiceMock, provideStoreServiceMock, StoreServiceMock } from '@ngxp/store-service/testing';
import { getBook } from 'apps/store-service-sample/src/test/books';
import { BookStoreService } from '../../shared/books/book-store.service';
import { NewBookComponent } from './new-book.component';
describe('NewBookComponent', () => {
let component: NewBookComponent;
let fixture: ComponentFixture<NewBookComponent>;
let bookStoreService: StoreServiceMock<BookStoreService>;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
FormsModule
],
declarations: [
NewBookComponent
],
providers: [
provideStoreServiceMock(BookStoreService)
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(NewBookComponent);
bookStoreService = getStoreServiceMock(BookStoreService);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('dispatches an AddBookAction onAddBook', () => {
const book = getBook();
component.book = book;
const addBookSpy = jest.spyOn(bookStoreService, 'addBook');
component.addBook(new Event('submit'));
expect(addBookSpy).toHaveBeenCalledWith({ book });
});
});