externalNotepadAdapter <Notes>
Implements
- ChainableSetter<Notes>
Index
Constructors
externalconstructor
Type parameters
- Notes: Record<any, any>
Returns NotepadAdapter<Notes>
Methods
externalhas
Type parameters
- Subject: string | number | symbol
Parameters
externalsubject: Subject
A subject (name) that uniquely identifies a given note
Returns QuestionAdapter<boolean>
Question that resolves to
true
if the note exists,false
otherwise
externalget
Type parameters
- Subject: string | number | symbol
Parameters
externalsubject: Subject
A subject (name) that uniquely identifies a given note
Returns QuestionAdapter<Notes[Subject]>
The value of the previously recorded note.
externalset
Resolves a given
Answerable<value>
and stores it in the notepad, uniquely identified by itssubject
.Pro tip: calls to
set
can be chained and result in an accumulation of values to be recorded in theNotepad
. Those values are resolved and recorded when theInteraction
returned by this method is performed by anActor
.If a note identified by a given
subject
is set multiple times, the last call wins.import { actorCalled, notes, TakeNotes } from '@serenity-js/core'
import { Ensure, equals } from '@serenity-js/assertions'
interface MyNotes {
stringNote: string;
numberNote: number;
}
await actorCalled('Alice')
.whoCan(TakeNotes.usingAnEmptyNotepad<MyNotes>());
.attemptsTo(
notes<MyNotes>()
.set('stringNote', 'example')
.set('numberNote', Promise.resolve(42))
.set('stringNote', 'another example'),
Ensure.equal(notes().toJSON(), {
firstNote: 'another example',
secondNote: 42,
})
)Learn more
Type parameters
- Subject: string | number | symbol
Parameters
externalsubject: Subject
A subject (name) that uniquely identifies a given note
externalvalue: Answerable<Notes[Subject]>
The value to record
Returns ChainableSetter<Notes> & Interaction
externaldelete
Removes the note identified by
subject
from the notepad.Using as an
Interaction
import { actorCalled, Check, Log, notes } from '@serenity-js/core'
import { isPresent } from '@serenity-js/assertions'
interface MyNotes {
myNote: string;
}
await actorCalled('Alice')
.whoCan(TakeNotes.using(Notepad.empty<MyNotes>()))
.attemptsTo(
notes<MyNotes>().set('myNote', 'example value'),
notes<MyNotes>().delete('myNote'),
Check.whether(notes<MyNotes>().get('myNote'), isPresent())
.andIfSo(
Log.the('myNote is present'),
)
.otherwise(
Log.the('myNote was deleted'),
)
)
// logs: myNote was deletedUsing as a
Question
import { actorCalled, Check, Log, notes } from '@serenity-js/core'
import { isTrue } from '@serenity-js/assertions'
interface MyNotes {
myNote: string;
}
await actorCalled('Alice')
.whoCan(TakeNotes.using(Notepad.empty<MyNotes>()))
.attemptsTo(
notes<MyNotes>().set('myNote', 'example value'),
Check.whether(notes<MyNotes>().delete('myNote'), isTrue())
.andIfSo(
Log.the('myNote was deleted'),
)
.otherwise(
Log.the('myNote could not be deleted because it was not set'),
)
)
// logs: myNote was deletedLearn more
Type parameters
- Subject: string | number | symbol
Parameters
externalsubject: Subject
Returns QuestionAdapter<boolean>
When used as a
Question
, resolves totrue
if the item in the Notepad object existed and has been removed,false
otherwise.
externalclear
Deletes all the notes stored in this notepad.
import { actorCalled, notes } from '@serenity-js/core'
import { isTrue } from '@serenity-js/assertions'
interface MyNotes {
myNote: string;
}
await actorCalled('Alice')
.whoCan(TakeNotes.using(Notepad.empty<MyNotes>()))
.attemptsTo(
notes<MyNotes>().set('myNote', 'example value'),
Log.the(notes<MyNotes>().size()), // emits 1
notes<MyNotes>().clear(),
Log.the(notes<MyNotes>().size()), // emits 0
)Learn more
Returns Interaction
externalsize
Returns the number of notes stored in the notepad.
import { actorCalled, notes } from '@serenity-js/core'
import { isTrue } from '@serenity-js/assertions'
interface MyNotes {
myNote: string;
}
await actorCalled('Alice')
.whoCan(TakeNotes.using(Notepad.empty<MyNotes>()))
.attemptsTo(
Log.the(notes<MyNotes>().size()), // emits 0
notes<MyNotes>().set('myNote', 'example value'),
Log.the(notes<MyNotes>().size()), // emits 1
)Learn more
Returns QuestionAdapter<number>
externaltoJSON
Produces a
QuestionAdapter
that resolves to aJSONObject
representing the resolved notes stored in the notepad.Note that serialisation to JSON will simplify some data types that might not be serialisable by default, but are commonly used in data structures representing actor's notes. For example a
Map
will be serialised as a regular JSON object, aSet
will be serialised asArray
.Additionally, notepad assumes that the data structure you use it with does not contain cyclic references.
To learn more about the serialisation mechanism used by the notepad, please refer to TinyTypes documentation.
import { actorCalled, notes } from '@serenity-js/core'
await actorCalled('Alice')
.whoCan(TakeNotes.using(Notepad.with({
aSet: new Set(['apples', 'bananas', 'cucumbers']),
aPromisedValue: Promise.resolve(42),
aString: 'example'
})))
.attemptsTo(
Log.the(notes().toJSON()),
)
// emits: {
// aSet: ['apples', 'bananas', 'cucumbers']
// aPromisedValue: 42,
// aString: 'example',
// }Returns QuestionAdapter<JSONObject>
externaltoString
Returns string
Serenity/JS Screenplay Pattern-style adapter for the
Notepad
, that makes it easier for the actors to access its APIs.See
TakeNotes
,Notepad
andnotes
for more examples.