Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an identity function to make filtering lists of objects easier #1420

Open
jan-molak opened this issue Dec 7, 2022 · 1 comment
Open
Labels
developer experience Improvements to the developer experience of using Serenity/JS @serenity-js/core @serenity-js/rest

Comments

@jan-molak
Copy link
Member

Serenity/JS should provide a Screenplay Pattern-style identity function to make it easier to filter lists of objects, e.g. in API tests.

For example:

interface Person {
  name: string;
}

const entries = [ { name: 'Alice' }, { name: 'Bob' }, { name: 'Clarice' } ];

const list = List.of(items);

await actorCalled('Lisa').attemptsTo(
  Ensure.that(
    List.of<Person>(entries)
      .where(List.entry<Person>().name, endsWith('ice')),
    equals([
      'Alice',
      'Clarice',
    ])
  )
)

The new "identity function" should allow for syntax like:

      .where(List.entry<Person>().name, endsWith('ice')),

and

      .where(List.entry<Person>(), property('name', endsWith('ice'))),

Candidate names:

List.entry<T>()
List.item<T>()
@jan-molak jan-molak added this to the 3.0 milestone Dec 7, 2022
@Dapangma
Copy link

Dapangma commented Dec 8, 2022

I would rather name it List.item(), since you expect to have items in a List, while entries are expected from a dictionary (map).

@jan-molak jan-molak modified the milestones: 3.0, 3.1 Dec 19, 2022
@jan-molak jan-molak changed the title Serenity/JS 3.0 - Provide an identity function to make filtering lists of objects easier Provide an identity function to make filtering lists of objects easier Jun 1, 2023
@jan-molak jan-molak added @serenity-js/rest developer experience Improvements to the developer experience of using Serenity/JS labels Jun 1, 2023
@jan-molak jan-molak removed this from the 3.1 milestone Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer experience Improvements to the developer experience of using Serenity/JS @serenity-js/core @serenity-js/rest
Projects
None yet
Development

No branches or pull requests

2 participants