|
1 | 1 | import { Component } from '@angular/core';
|
2 |
| -import { render } from '@testing-library/angular'; |
| 2 | +import { render, waitFor } from '@testing-library/angular'; |
3 | 3 | import '@testing-library/jest-dom';
|
4 | 4 | import { configureStore, createSlice } from '@reduxjs/toolkit';
|
5 | 5 | import { provideRedux, injectDispatch, injectSelector } from '../public-api';
|
6 | 6 | import { userEvent } from '@testing-library/user-event';
|
| 7 | +import { createStore } from 'redux'; |
7 | 8 |
|
8 | 9 | const user = userEvent.setup();
|
9 | 10 |
|
@@ -70,3 +71,32 @@ it('injectSelector should work with reactivity', async () => {
|
70 | 71 |
|
71 | 72 | expect(getByText('Count: 1')).toBeInTheDocument();
|
72 | 73 | });
|
| 74 | + |
| 75 | +it('should show a value dispatched during ngOnInit', async () => { |
| 76 | + const store = configureStore({ |
| 77 | + reducer: { |
| 78 | + counter: counterSlice.reducer, |
| 79 | + }, |
| 80 | + }); |
| 81 | + |
| 82 | + @Component({ |
| 83 | + selector: 'app-root', |
| 84 | + standalone: true, |
| 85 | + template: '<p>Count: {{count()}}</p>', |
| 86 | + }) |
| 87 | + class Comp { |
| 88 | + count = injectSelector((state: any) => state.counter.value); |
| 89 | + dispatch = injectDispatch(); |
| 90 | + increment = counterSlice.actions.increment; |
| 91 | + |
| 92 | + ngOnInit() { |
| 93 | + this.dispatch(this.increment()); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + const { getByText } = await render(Comp, { |
| 98 | + providers: [provideRedux({ store })], |
| 99 | + }); |
| 100 | + |
| 101 | + await waitFor(() => expect(getByText('Count: 1')).toBeInTheDocument()); |
| 102 | +}); |
0 commit comments