Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
UnitTest.asynctest('NgModelTest', (success, failure) => {
const createComponent = (componentType: Type) => {
TestBed.configureTestingModule({
imports: [EditorModule, FormsModule],
declarations: [componentType]
}).compileComponents();
return TestBed.createComponent(componentType);
};
const fakeKeyUp = (editor: any, char: string) => {
editor.selection.setContent(char);
editor.fire('keyup');
};
const cSetup = Chain.async((_, next) => {
const fixture = createComponent(EditorWithNgModelComponent);
fixture.detectChanges();
const editorDebugElement = fixture.debugElement.query(By.directive(EditorComponent));
const ngModel = editorDebugElement.injector.get(NgModel);
const editorComponent = editorDebugElement.componentInstance;
editorComponent.onInit.subscribe(() => {
editorComponent.editor.on('SkinLoaded', () => {
setTimeout(() => {
next({ fixture, editorDebugElement, editorComponent, ngModel });
}, 0);
});
});
});
const cTeardown = Chain.op(() => {
const cSetup = (createElement: (Ed: TestEditor) => JSX.Element) => {
return Chain.async((_, next, die) => {
const root = document.createElement('div');
document.body.append(root);
const onEditorLoaded: OnEditorLoaded = (editor, ref) => {
Option.from(ref.current)
.map(ReactDOM.findDOMNode)
.filter((val) => val instanceof Element)
.fold(() => die('Could not find DOMNode'), (DOMNode) => {
next({
ref,
root,
editor,
DOMNode: DOMNode as Element
});
});
};