Skip to content
Permalink
Browse files
fix(assertions): wordsmithing
  • Loading branch information
jan-molak committed Mar 7, 2019
1 parent eb0fc60 commit bd13c4debaccac8e959fddae73bc5724ff7e83e8
@@ -2,38 +2,38 @@ import 'mocha';

import { expect } from '@integration/testing-tools';
import { Actor, AssertionError, Question } from '@serenity-js/core';
import { containAtLeastOneThat, Ensure, equals, isGreaterThan } from '../../src';
import { containAtLeastOneItemThat, Ensure, equals, isGreaterThan } from '../../src';

describe('containAtLeastOneThat', () => {
describe('containAtLeastOneItemThat', () => {

const Astrid = Actor.named('Astrid');

/** @test {containAtLeastOneThat} */
/** @test {containAtLeastOneItemThat} */
it(`allows for the actor flow to continue when the "actual" includes at least one item that meets the expectation`, () => {
return Astrid.attemptsTo(
Ensure.that([ 0, 1, 2 ], containAtLeastOneThat(isGreaterThan(1))),
Ensure.that([ 0, 1, 2 ], containAtLeastOneItemThat(isGreaterThan(1))),
);
});

/** @test {containAtLeastOneThat} */
/** @test {containAtLeastOneItemThat} */
it(`breaks the actor flow when "actual" does not include at least one item that meets the expectation`, () => {
return expect(Astrid.attemptsTo(
Ensure.that([ 0, 1, 2 ], containAtLeastOneThat(equals(7))),
)).to.be.rejectedWith(AssertionError, `Expected [ 0, 1, 2 ] to contain at least one that does equal 7`);
Ensure.that([ 0, 1, 2 ], containAtLeastOneItemThat(equals(7))),
)).to.be.rejectedWith(AssertionError, `Expected [ 0, 1, 2 ] to contain at least one item that does equal 7`);
});

/** @test {containAtLeastOneThat} */
/** @test {containAtLeastOneItemThat} */
it(`breaks the actor flow when "actual" is an empty list`, () => {
return expect(Astrid.attemptsTo(
Ensure.that([], containAtLeastOneThat(equals(42))),
)).to.be.rejectedWith(AssertionError, `Expected [ ] to contain at least one that does equal 42`);
Ensure.that([], containAtLeastOneItemThat(equals(42))),
)).to.be.rejectedWith(AssertionError, `Expected [ ] to contain at least one item that does equal 42`);
});

/** @test {atLeastOne} */
it(`contributes to a human-readable description`, () => {
const numbers = () => Question.about('list of numbers', actor => [ 0, 1, 2 ]);

expect(Ensure.that(numbers(), containAtLeastOneThat(isGreaterThan(1))).toString())
.to.equal(`#actor ensures that list of numbers does contain at least one that does have value greater than 1`);
expect(Ensure.that(numbers(), containAtLeastOneItemThat(isGreaterThan(1))).toString())
.to.equal(`#actor ensures that list of numbers does contain at least one item that does have value greater than 1`);
});
});
@@ -4,6 +4,7 @@ import { expect } from '@integration/testing-tools';
import { Actor, AssertionError } from '@serenity-js/core';
import {
and,
containAtLeastOneItemThat,
contains,
endsWith,
Ensure,
@@ -95,6 +96,24 @@ describe('not', () => {
});
});

describe('containAtLeastOneItemThat,', () => {

/** @test {not} */
/** @test {containAtLeastOneItemThat} */
it(`produces a sensible error message`, () => {
return expect(Astrid.attemptsTo(
Ensure.that([ 1, 2, 3 ], not(containAtLeastOneItemThat(equals(2))),
))).to.be.rejectedWith(AssertionError, `Expected [ 1, 2, 3 ] to not contain at least one item that does equal 2`);
});

/** @test {not} */
/** @test {containAtLeastOneItemThat} */
it(`contributes to a human-readable description`, () => {
expect(Ensure.that([ 'H', 'e', 'l', 'l', 'o' ], not(containAtLeastOneItemThat(equals('o')))).toString())
.to.equal(`#actor ensures that [ 'H', 'e', 'l', 'l', 'o' ] does not contain at least one item that does equal 'o'`);
});
});

describe('endsWith,', () => {

/** @test {not} */
@@ -3,11 +3,11 @@ import { formatted } from '@serenity-js/core/lib/io';
import { Expectation } from '../Expectation';
import { ExpectationMet, ExpectationNotMet, Outcome } from '../outcomes';

export function containAtLeastOneThat<Actual>(expectation: Expectation<any, Actual>): Expectation<any, Actual[]> {
return new ContainAtLeastOneThatMeetsExpectation(expectation);
export function containAtLeastOneItemThat<Actual>(expectation: Expectation<any, Actual>): Expectation<any, Actual[]> {
return new ContainAtLeastOneItemThatMeetsExpectation(expectation);
}

class ContainAtLeastOneThatMeetsExpectation<Expected, Actual> extends Expectation<Expected, Actual[]> {
class ContainAtLeastOneItemThatMeetsExpectation<Expected, Actual> extends Expectation<Expected, Actual[]> {
constructor(private readonly expectation: Expectation<Expected, Actual>) {
super();
}
@@ -23,6 +23,6 @@ class ContainAtLeastOneThatMeetsExpectation<Expected, Actual> extends Expectatio
}

toString(): string {
return formatted `contain at least one that does ${ this.expectation }`;
return formatted `contain at least one item that does ${ this.expectation }`;
}
}
@@ -1,6 +1,6 @@
export * from './and';
export * from './contains';
export * from './containAtLeastOneThat';
export * from './containAtLeastOneItemThat';
export * from './endsWith';
export * from './equals';
export * from './includes';

0 comments on commit bd13c4d

Please sign in to comment.