-
Testing with the below results in this error:
import {Component, Directive, Input} from '@angular/core'
import {createComponentFactory, Spectator} from '@ngneat/spectator/jest'
import {MockBuilder} from 'ng-mocks'
@Directive({
selector: 'a[appLink]',
standalone: true
})
export class LinkDirective {
@Input() appLink!: string
}
@Component({
selector: '',
standalone: true,
imports: [LinkDirective],
template: '<a appLink="foo"></a>'
})
class ExampleComponent {
}
describe('ExampleComponent', () => {
let spectator: Spectator<ExampleComponent>
let component: ExampleComponent
const dependencies = MockBuilder([ExampleComponent], [LinkDirective]).build()
const createComponent = createComponentFactory({
component: ExampleComponent,
...dependencies
})
beforeEach(() => {
spectator = createComponent()
component = spectator.component
})
it('should create', () => {
expect(component).toBeTruthy()
})
}) Based on your reply to the other discussion, I thought you might mean I had to do this instead: const dependencies = MockBuilder(ExampleComponent)
.mock(LinkDirective)
.build() but that has the same error. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
UpdatedI think, it has been fixed already by https://github.com/help-me-mom/ng-mocks/releases/tag/v14.1.0, could you verify if it works for you? OriginalIn your example, because const dependencies = MockBuilder(ExampleComponent).build(); I know that docs are hard to read, I'm very sorry for that, simply not much time to improve them. Anyway, |
Beta Was this translation helpful? Give feedback.
Updated
I think, it has been fixed already by https://github.com/help-me-mom/ng-mocks/releases/tag/v14.1.0, could you verify if it works for you?
Original
In your example, because
LinkDirective
has been imported byExampleComponent
, and you want to mock it, you should simply use:I know that docs are hard to read, I'm very sorry for that, simply not much time to improve them.
More info why and how is here: https://ng-mocks.sudo.eu/guides/component-standalone
Anyway,
MockBuilder([ExampleComponent], [LinkDirective]).build()
shouldn't throw, I'll double check what is wrong there and I'll try to fix it.