-
Notifications
You must be signed in to change notification settings - Fork 5
Testing DOM interactions
Click html element.
var click = testRunner.actions.click;
it('click test', () => {
var html = app.runHtml('<button class="my-element"></button>');
html.perform(
click.in('.my-element')
);
html.verify(
// assertions
)
});
In case of css selector belongs to
- multiple elements
- no element
click
method will throw Error
Wait for some delay.
var wait = testRunner.actions.wait;
We have to use done
parameter to tell runner that still there are some async operations.
it('async click test with wait', done => {
var html = app.runHtml('<button class="my-element"></button>');
html.perform(
click.in('.my-element'),
wait(200)
);
html.verify(
// assertions
done
)
});
Type some text into input field.
var type = testRunner.actions.type;
it('type test', () => {
var html = app.runHtml('<input class="my-element"></input>');
html.perform(
type('Some text').in('.my-element')
);
html.verify(
// assertions
)
});
Press key.
var keypress = testRunner.actions.keypress;
it('keypress test', () => {
var html = app.runHtml('<div class="my-element"></div>');
html.perform(
keypress(13).in('.my-element')
);
html.verify(
// assertions
)
});
Press key.
var keyup = testRunner.actions.keyup;
it('keyup test', () => {
var html = app.runHtml('<div class="my-element"></div>');
html.perform(
keyup(13).in('.my-element')
);
html.verify(
// assertions
)
});
Press key.
var keydown = testRunner.actions.keydown;
it('keydown test', () => {
var html = app.runHtml('<div class="my-element"></div>');
html.perform(
keydown(13).in('.my-element')
);
html.verify(
// assertions
)
});
Put mouse over element.
var mouseover = testRunner.actions.mouseover;
it('mouseover test', () => {
var html = app.runHtml('<div class="my-element"></div>');
html.perform(
mouseover.in('.my-element')
);
html.verify(
// assertions
)
});
In case of css selector belongs to
- multiple elements
- no element
mouseover
method will throw Error
Leave mouse from element.
var mouseleave = testRunner.actions.mouseleave;
it('mouseleave test', () => {
var html = app.runHtml('<div class="my-element"></div>');
html.perform(
mouseleave.in('.my-element')
);
html.verify(
// assertions
)
});
In case of css selector belongs to
- multiple elements
- no element
mouseleave
method will throw Error
Fires blur event for an element.
var blur = testRunner.actions.blur;
it('blur test', () => {
var html = app.runHtml('<input class="my-element">');
html.perform(
blur.from('.my-element')
);
html.verify(
// assertions
)
});
In case of css selector belongs to
- multiple elements
- no element
blur
method will throw Error
navigateTo(url)[.after(timeout)]
Navigate to url.
var navigateTo = testRunner.actions.navigateTo;
it('navigateTo action test', () => {
var html = app.runHtml('<div></div>');
html.perform(
navigateTo('/user/13/address')
);
html.verify(
// assertions
)
});
Scope apply on element.
var apply = testRunner.actions.apply;
it('apply action test', () => {
var html = app.runHtml('<div></div>');
html.perform(
apply(/*co tu trzeba wpisać*/)
);
html.verify(
// assertions
)
});
Expect html element to have met some conditions.
var expectElement = testRunner.actions.expectElement;
it('expectElement action test', () => {
var html = app.runHtml('<div class="my-element">Some text</div>');
html.perform(
expectElement('.my-element').toContainText('Some text')
);
html.verify(
// assertions
)
});
Listen to Angular event.
var listenTo = testRunner.actions.listenTo;
it('listenTo action test', () => {
var dataFromEvent;
var html = app.runHtml('<div></div>');
html.perform(
listenTo('someEvent', function (data) {
dataFromEvent = data;
}),
);
$rootScope.$emit('someEvent', 'Event data!');
expect(dataFromEvent).toEqual('Event data!');
});
Publish Angular event.
var publishEvent = testRunner.actions.publishEvent;
it('publishEvent test', () => {
var dataFromEvent;
var html = app.runHtml('<div></div>');
html.perform(
listenTo('someEvent', function (data) {
dataFromEvent = data;
}),
);
html.perform(
publishEvent('externalGreeting', 'Event data!')
);
expect(dataFromEvent).toEqual('Event data!');
});
Select element to perform action on.
Select element to perform action on.
Perform action after delay.