Skip to content

Commit

Permalink
fix(schematics): update schematics for v4 API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkluijk committed Aug 26, 2019
1 parent 9159b78 commit 4175b30
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { <%= classify(name)%>Component } from './<%= dasherize(name)%>.component';
import { createHostComponentFactory, SpectatorWithHost } from '@ngneat/spectator';
import { Component } from '@angular/core';
import { createHostFactory, SpectatorHost } from '@ngneat/spectator';

import { <%= classify(name)%>Component } from './<%= dasherize(name)%>.component';

@Component({ selector: 'custom-host', template: '' })
@Component({ template: '' })
class CustomHostComponent {
title = 'Custom HostComponent';
}

describe('<%= classify(name)%>Component', () => {
let host: SpectatorWithHost<<%= classify(name)%>Component, CustomHostComponent>;
let host: SpectatorHost<<%= classify(name)%>Component, CustomHostComponent>;

const createHost = createHostComponentFactory({ component: <%= classify(name)%>Component, host: CustomHostComponent });
const createHost = createHostFactory({
component: <%= classify(name)%>Component,
host: CustomHostComponent
});

it('should display the host component title', () => {
host = createHost(`<zippy [title]="title"></zippy>`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import { createHostFactory, SpectatorHost } from '@ngneat/spectator';

import { <%= classify(name)%>Component } from './<%= dasherize(name)%>.component';
import { createHostComponentFactory, SpectatorWithHost } from '@ngneat/spectator';

describe('<%= classify(name)%>Component', () => {
let host: SpectatorWithHost<<%= classify(name)%>Component>;
const createHost = createHostComponentFactory(<%= classify(name)%>Component);
let spectator: SpectatorHost<<%= classify(name)%>Component>;

const createHost = createHostFactory(<%= classify(name)%>Component);

it('should create', () => {
host = createHost(`<zippy title="Zippy title"></zippy>`);
expect(host.component).toBeTruthy();
spectator = createHost(`<zippy title="Zippy title"></zippy>`);
expect(spectator.component).toBeTruthy();
});

it('should...', () => {
host = createHost(`<zippy title="Zippy title">Zippy content</zippy>`);
host.click('.zippy__title');
expect(host.query('.arrow')).toHaveText('Close');
spectator = createHost(`<zippy title="Zippy title">Zippy content</zippy>`);
spectator.click('.zippy__title');
expect(spectator.query('.arrow')).toHaveText('Close');
});

it('should...', () => {
host = createHost(`<zippy title="Zippy title"></zippy>`);
host.click('.zippy__title');
spectator = createHost(`<zippy title="Zippy title"></zippy>`);
spectator.click('.zippy__title');
expect(host.query('.zippy__content')).toExist();
host.click('.zippy__title');
spectator.click('.zippy__title');
expect('.zippy__content').not.toExist();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Spectator, createComponentFactory } from '@ngneat/spectator';

import { <%= classify(name)%>Component } from './<%= dasherize(name)%>.component';
import { Spectator, createTestComponentFactory } from '@ngneat/spectator';

describe('<%= classify(name)%>Component', () => {
let spectator: Spectator<<%= classify(name)%>Component>;
const createComponent = createTestComponentFactory(<%= classify(name)%>Component);

const createComponent = createComponentFactory(<%= classify(name)%>Component);

it('should create', () => {
spectator = createComponent();

expect(spectator.component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator';

import { <%= classify(name)%>Directive } from './<%= dasherize(name)%>.directive';
import { createHostComponentFactory, SpectatorWithHost } from '@ngneat/spectator';

describe('<%= classify(name)%>Directive ', () => {
let host: SpectatorWithHost<<%= classify(name)%>Directive>;
let spectator: SpectatorDirective<<%= classify(name)%>Directive>;

const createHost = createHostComponentFactory(<%= classify(name)%>Directive);
const createDirective = createDirectiveFactory(<%= classify(name)%>Directive);

it('should change the background color', () => {
host = createHost(`<div highlight>Testing <%= classify(name)%>Directive</div>`);
spectator = createDirective(`<div highlight>Testing <%= classify(name)%>Directive</div>`);

host.dispatchMouseEvent(host.element, 'mouseover');
spectator.dispatchMouseEvent(spectator.element, 'mouseover');

expect(host.element).toHaveStyle({
expect(spectator.element).toHaveStyle({
backgroundColor: 'rgba(0,0,0, 0.1)'
});

host.dispatchMouseEvent(host.element, 'mouseout');
expect(host.element).toHaveStyle({
spectator.dispatchMouseEvent(spectator.element, 'mouseout');
expect(spectator.element).toHaveStyle({
backgroundColor: '#fff'
});
});
Expand Down

0 comments on commit 4175b30

Please sign in to comment.