#test my component with jasmine
9 messages · Page 1 of 1 (latest)
thanks i try this
I use this to stub a route: https://github.com/Ninja-Squad/ngx-speculoos#routing-helper (and I use the library for my tests in general)
i cannot add another extern library :/
You can also trigger navigation in your test and pass the query params you want.
@Component({ template: `<router-outlet></router-outlet>` })
class TestComponent {}
describe("Your test", () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
imports: [
RouterTestingModule.withRoutes({
path: 'root',
component: YourComponent
})
]
})
})
it("should navigate", fakeAsync(() => {
const fixture = TestBed.createComponent(TestComponent)
const router = TestBed.inject(Router)
// navigate to "/root?id=1"
router.navigate(['/root'], { queryParams: { id: 1 }})
flush()
// add your expectations here
}))
})
it('the query params is a type date', () => {
const oldDateRange = component.dateRange;
const date = LocalDate.parse("2022-08-01");
router.navigate([''], {queryParams: {date: date}})
expect(component.dateRange.from).toEqual(LocalDate.parse("2022-08-01"))
}) ``` the probleme i would like to see if the value of my component class is changed
in fact, I want to send a parameter in my query and that my component is updated thanks to this parameter and then I want to see if the variable which is changed thanks to the parameter has been
Well, that's what the last line of your test does, doesn't it? What's the issue?
When I run my test my date has not changed it is still today while in my parameter the date I put will change the date variable of my component