Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('emits the events so that the details of the script being executed can be reported', () => {
const
frozenClock = new Clock(() => new Date('1970-01-01')),
theStage = stage(new UIActors(), frozenClock),
actor = theStage.theActorCalled('Ashwin');
sinon.spy(theStage, 'announce');
return actor.attemptsTo(
ExecuteScript.sync(`console.log('hello world');`),
Ensure.that(Browser.log(), containAtLeastOneItemThat(property('message', includes('hello world')))),
).then(() => {
const events = (theStage.announce as sinon.SinonSpy).getCalls().map(call => call.lastArg);
expect(events).to.have.lengthOf(5);
expect(events[ 0 ]).to.be.instanceOf(ActivityStarts);
expect(events[ 1 ]).to.be.instanceOf(ArtifactGenerated);
expect(events[ 2 ]).to.be.instanceOf(ActivityFinished);
const artifactGenerated = events[ 1 ] as ActivityRelatedArtifactGenerated;
expect(artifactGenerated.name.value).to.equal(`Script source`);
expect(artifactGenerated.artifact.equals(TextData.fromJSON({
contentType: 'text/javascript;charset=UTF-8',
data: 'console.log(\'hello world\');',
}))).to.equal(true, JSON.stringify(artifactGenerated.artifact.toJSON()));
it('allows the actor to read the browser log entries', () => Bernie.attemptsTo(
Navigate.to(pageFromTemplate(`
`)),
Ensure.that(Browser.log(), containAtLeastOneItemThat(property('message', includes('Hello from the console!')))),
));
.then(() => Joe.attemptsTo(
Ensure.that(Browser.log(), containAtLeastOneItemThat(property('message', includes('execute-script-sample.js.invalid - Failed to load resource')))),
)));