@serenity-js/assertions
TypeScript icon, indicating that this package has built-in type declarations

3.31.15 • Public • Published

Serenity/JS

Follow Serenity/JS on LinkedIn Watch Serenity/JS on YouTube Join Serenity/JS Community Chat Support Serenity/JS on GitHub

Serenity/JS is an innovative open-source framework designed to make acceptance and regression testing of complex software systems faster, more collaborative and easier to scale.

⭐️ Get started with Serenity/JS!

👋 Join the Serenity/JS Community!

Serenity/JS Assertions

@serenity-js/assertions is an assertions library implementing the Screenplay Pattern.

Installation

To install this module, run the following command in your computer terminal:

npm install --save-dev @serenity-js/core @serenity-js/assertions

Performing verifications using Ensure

import { Ensure, endsWith } from '@serenity-js/assertions'
import { actorCalled } from '@serenity-js/core'
import { Navigate, Page } from '@serenity-js/web'

await actorCalled('Erica').attemptsTo(
    Navigate.to('https://serenity-js.org'),
    Ensure.that(
        Page.current().title(), 
        endsWith('Serenity/JS')
    ),
)

Controlling execution flow using Check

import { actorCalled } from '@serenity-js/core'
import { Check } from '@serenity-js/assertions' 
import { Click, isVisible } from '@serenity-js/protractor'

await actorCalled('Erica').attemptsTo(
    Check.whether(NewsletterModal, isVisible())
        .andIfSo(Click.on(CloseModalButton)),
)

Synchronising the test with the System Under Test using Wait

import { actorCalled } from '@serenity-js/core'
import { Click, isVisible, Wait } from '@serenity-js/protractor'

await actorCalled('Erica').attemptsTo(
    Wait.until(CloseModalButton, isVisible()),
    Click.on(CloseModalButton)
)

Defining custom expectations using Expectation.thatActualShould

import { actorCalled } from '@serenity-js/core'
import { Expectation, Ensure } from '@serenity-js/assertions'

function isDivisibleBy(expected: Answerable<number>): Expectation<number> {
    return Expectation.thatActualShould<number, number>('have value divisible by', expected)
        .soThat((actualValue, expectedValue) => actualValue % expectedValue === 0)
}

await actorCalled('Erica').attemptsTo(
    Ensure.that(4, isDivisibleBy(2)),
)

Composing expectations using Expectation.to

import { actorCalled } from '@serenity-js/core'
import { Expectation, Ensure, and, or, isGreaterThan, isLessThan, equals  } from '@serenity-js/assertions'

function isWithin(lowerBound: number, upperBound: number) {
    return Expectation
        .to(`have value within ${ lowerBound } and ${ upperBound }`)
        .soThatActual(and(
           or(isGreaterThan(lowerBound), equals(lowerBound)),
           or(isLessThan(upperBound), equals(upperBound)),
        ))
}

await actorCalled('Erica').attemptsTo(
    Ensure.that(5, isWithin(3, 6)),
)

📣 Stay up to date

New features, tutorials, and demos are coming soon! Follow Serenity/JS on LinkedIn, subscribe to Serenity/JS channel on YouTube and join the Serenity/JS Community Chat to stay up to date! Please also make sure to star ⭐️ Serenity/JS on GitHub to help others discover the framework!

Follow Serenity/JS on LinkedIn Watch Serenity/JS on YouTube Join Serenity/JS Community Chat GitHub stars

💛 Support Serenity/JS

If you appreciate all the effort that goes into making sophisticated tools easy to work with, please support our work and become a Serenity/JS GitHub Sponsor today!

GitHub Sponsors

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.31.15
1,510latest

Version History

VersionDownloads (Last 7 Days)Published
3.31.15
1,510
3.31.14
690
3.31.13
3,610
3.31.12
1,667
3.31.10
620
3.31.9
23
3.31.8
28
3.31.7
75
3.31.6
38
3.31.5
24
3.31.4
46
3.31.3
0
3.31.2
0
3.31.1
4
3.31.0
191
3.30.0
302
3.29.5
45
3.29.4
739
3.29.3
0
3.29.2
19
3.28.0
9
3.27.0
0
3.26.1
7
3.26.0
157
3.25.5
71
3.25.4
1
3.25.3
45
3.25.2
173
3.25.1
5
3.25.0
0
3.24.1
1
3.24.0
41
3.23.2
743
3.23.1
0
3.23.0
2
3.22.4
21
3.22.3
0
3.22.2
0
3.22.1
11
3.22.0
13
3.21.2
1,255
3.21.1
278
3.21.0
0
3.20.0
0
3.19.0
0
3.18.1
149
3.18.0
0
3.17.0
3
3.16.2
0
3.16.1
0
3.16.0
0
3.15.1
0
3.15.0
36
3.14.2
281
3.14.1
0
3.14.0190
3.13.30
3.13.20
3.13.12
3.13.0126
3.12.021
3.11.10
3.11.01
3.10.40
3.10.30
3.10.20
3.10.10
3.10.01
3.9.135
3.9.07
3.8.01
3.7.20
3.7.10
3.7.00
3.6.10
3.6.00
3.5.00
3.4.20
3.4.11
3.4.00
3.3.10
3.3.00
3.2.10
3.2.01
3.1.646
3.1.50
3.1.313
3.1.20
3.1.10
3.1.01
3.0.10
3.0.00
3.0.0-rc.450
3.0.0-rc.440
3.0.0-rc.430
3.0.0-rc.428
3.0.0-rc.410
3.0.0-rc.402
3.0.0-rc.390
3.0.0-rc.380
3.0.0-rc.370
3.0.0-rc.360
3.0.0-rc.350
3.0.0-rc.340
3.0.0-rc.330
3.0.0-rc.320
3.0.0-rc.310
3.0.0-rc.301
3.0.0-rc.291
3.0.0-rc.281
3.0.0-rc.272
3.0.0-rc.262
3.0.0-rc.252
3.0.0-rc.240
3.0.0-rc.230
2.33.101,399
3.0.0-rc.220
3.0.0-rc.210
3.0.0-rc.200
3.0.0-rc.190
3.0.0-rc.180
2.33.928
3.0.0-rc.170
2.33.80
2.33.70
3.0.0-rc.160
2.33.60
3.0.0-rc.150
2.33.510
2.33.41
3.0.0-rc.140
2.33.321
3.0.0-rc.130
3.0.0-rc.120
2.33.20
3.0.0-rc.110
2.33.10
3.0.0-rc.100
2.33.00
3.0.0-rc.90
3.0.0-rc.80
3.0.0-rc.70
3.0.0-rc.61
2.32.794
2.32.60
3.0.0-rc.50
3.0.0-rc.40
3.0.0-rc.30
3.0.0-rc.20
3.0.0-rc.10
3.0.0-rc.00
2.32.57
2.32.4330
2.32.30
2.32.227
2.32.12
2.32.014
2.31.10
2.31.00
2.30.338
2.30.20
2.30.111
2.30.01
2.29.90
2.29.80
2.29.70
2.29.60
2.29.50
2.29.40
2.29.30
2.29.10
2.29.00
2.28.15
2.28.00
2.27.10
2.27.00
2.26.20
2.26.00
2.25.90
2.25.84
2.25.716
2.25.60
2.25.50
2.25.40
2.25.30
2.25.20
2.25.10
2.25.00
2.24.10
2.24.0185
2.23.20
2.23.10
2.23.00
2.22.00
2.21.00
2.20.114
2.20.00
2.19.100
2.19.91
2.19.80
2.19.70
2.19.60
2.19.50
2.19.40
2.19.30
2.19.20
2.19.10
2.19.00
2.18.20
2.18.11
2.18.00
2.17.160
2.17.150
2.17.140
2.17.130
2.17.120
2.17.110
2.17.100
2.17.50
2.17.40
2.17.30
2.17.20
2.17.10
2.17.00
2.16.00
2.15.00
2.14.00
2.13.10
2.13.00
2.12.2749
2.12.10
2.12.00
2.11.40
2.11.30
2.11.20
2.11.10
2.11.00
2.10.30
2.10.20
2.10.10
2.10.00
2.7.01
2.6.00
2.5.20
2.5.10
2.5.00
2.4.10
2.4.00
2.3.60
2.3.50
2.3.40
2.3.30
2.3.10
2.2.228
2.2.10
2.1.51
2.1.40
2.1.30
2.1.20
2.1.10
2.1.00
2.0.70
2.0.20
2.0.10

Package Sidebar

Install

npm i @serenity-js/assertions

Weekly Downloads

15,935

Version

3.31.15

License

Apache-2.0

Unpacked Size

206 kB

Total Files

126

Last publish

Collaborators

  • jan-molak