Skip to main content

externalNotepad <Notes>

Stores notes recorded by an Actor.

See TakeNotes and notes for more usage examples.

Sharing a notepad between actors

import { Actor, Cast, Notepad, TakeNotes } from '@serenity-js/core'

interface MyNotes {
auth: {
username: string;
password: string;
}
}

export class Actors implements Cast {

// initialise a shared notepad when the Actors class is initialised
private readonly sharedNotepad = Notepad.with<MyNotes>({
auth: {
username: 'test-user',
password: 'SuperSecretP@ssword!',
}
});

prepare(actor: Actor): Actor {
switch (actor.name) {
case 'Alice':
case 'Bob':
// Alice and Bob will share their notepad
return actor.whoCan(TakeNotes.using(this.sharedNotepad));
default:
// other actors will get their own notepads
return actor.whoCan(TakeNotes.using(Notepad.empty<AuthCredentials>()));
}
}
}

Learn more

Hierarchy

  • TinyType
    • Notepad

Index

Methods

staticexternalempty

  • Instantiates a new empty Notepad.


    Type parameters

    • N: Record<any, any>

    Returns Notepad<N>

staticexternalwith

  • Instantiates a new Notepad with an initial state.

    import { actorCalled, Notepad, notes, TakeNotes } from '@serenity-js/core'
    import { Ensure, equals } from '@serenity-js/assertions'

    interface MyNotes {
    personalDetails: {
    firstName: string;
    lastName: string;
    }
    }

    actorCalled('Leonard')
    .whoCan(
    TakeNotes.using(
    Notepad.with<MyNotes>({
    personalDetails: {
    firstName: 'Leonard',
    lastName: 'McLaud',
    }
    })
    )
    )
    .attemptsTo(
    Ensure.that(
    notes<MyNotes>().get('personalDetails').firstName,
    equals('Leonard')
    ),
    )

    Type parameters

    • N: Record<any, any>

    Parameters

    • externalnotes: N

    Returns Notepad<N>

staticexternalnotes

externalhas

  • has<Subject>(subject: Subject): boolean
  • Checks if a note identified by subject exists in the notepad.


    Type parameters

    • Subject: string | number | symbol

    Parameters

    • externalsubject: Subject

      A subject (name) that uniquely identifies a given note

    Returns boolean

    true if the note exists, false otherwise

externalget

  • get<Subject>(subject: Subject): Notes[Subject]
  • Retrieves a note, identified by subject, from the notepad.

    @throws

    LogicError Throws a LogicError if the note with a given subject has never been recorded.


    Type parameters

    • Subject: string | number | symbol

    Parameters

    • externalsubject: Subject

      A subject (name) that uniquely identifies a given note

    Returns Notes[Subject]

    The value of the previously recorded note.

externalset

  • set<Subject>(subject: Subject, value: Notes[Subject]): Notepad<Notes>
  • Stores a given value uniquely identified by subject in the notepad.


    Type parameters

    • Subject: string | number | symbol

    Parameters

    • externalsubject: Subject

      A subject (name) that uniquely identifies a given note

    • externalvalue: Notes[Subject]

      The value to record.

    Returns Notepad<Notes>

externaldelete

  • delete<Subject>(subject: Subject): boolean
  • Removes the note identified by subject from the notepad.


    Type parameters

    • Subject: string | number | symbol

    Parameters

    • externalsubject: Subject

    Returns boolean

    true if the item in the Notepad object existed and has been removed, false otherwise.

externalclear

  • clear(): void
  • Deletes all the notes stored in this notepad.


    Returns void

externalsize

  • size(): number
  • Returns the number of notes stored in the notepad.


    Returns number

externalequals

  • equals(another: TinyType): boolean
  • @desc

    Compares two tiny types by value

    @example
    class Id extends TinyTypeOf<string>() {}

    const id = new Id(`3cc0852d-fda7-4f61-874e-0cfadbd6182a`);

    id.equals(id) === true
    @example
    class FirstName extends TinyTypeOf<string>() {}
    class LastName extends TinyTypeOf<string>() {}
    class Age extends TinyTypeOf<number>() {}

    class Person extends TinyType {
    constructor(public readonly firstName: FirstName,
    public readonly lastName: LastName,
    public readonly age: Age,
    ) {
    super();
    }
    }

    const p1 = new Person(new FirstName('John'), new LastName('Smith'), new Age(42)),
    p2 = new Person(new FirstName('John'), new LastName('Smith'), new Age(42));

    p1.equals(p2) === true

    Parameters

    • externalanother: TinyType

    Returns boolean

externaltoString

  • toString(): string
  • @desc

    Serialises the object to its string representation


    Returns string

externaltoJSON

  • toJSON(): JSONValue
  • @desc

    Serialises the object to a JSON representation.

    @example
    class FirstName extends TinyTypeOf<string>() {}

    const name = new FirstName('Jan');

    name.toJSON() === 'Jan'
    @example
    class FirstName extends TinyTypeOf<string>() {}
    class LastName extends TinyTypeOf<string>() {}
    class Age extends TinyTypeOf<number>() {}

    class Person extends TinyType {
    constructor(public readonly firstName: FirstName,
    public readonly lastName: LastName,
    public readonly age: Age,
    ) {
    super();
    }
    }

    const person = new Person(new FirstName('John'), new LastName('Smith'), new Age(42)),

    person.toJSON() === { firstName: 'John', lastName: 'Smith', age: 42 }

    Returns JSONValue