Example #1
0
  another_number(value: number): this {
    this.number2 = value;
    return this;
  }

  they_are_summed(): this {
    this.result = sum(this.number1, this.number2);
    return this;
  }

  the_result_is(expectedResult: number): this {
    expect(this.result).toEqual(expectedResult);
    return this;
  }
}

scenarios('sum', SumStage, ({ given, when, then }) => {
  return {
    two_numbers_can_be_added: scenario({}, () => {
      given()
        .a_number(1)
        .and()
        .another_number(2);

      when().they_are_summed();

      then().the_result_is(3);
    }),
  };
});
Example #2
0
  }

  they_are_summed(): this {
    this.result = sum(this.number1, this.number2);
    return this;
  }

  the_result_is(expectedResult: number): this {
    expect(this.result).toEqual(expectedResult);
    return this;
  }
}

scenarios('sum-parametrized', SumStage, ({ given, when, then }) => {
  return {
    two_numbers_can_be_added: scenario(
      {},
      parametrized3([[1, 2, 3], [2, 3, 5]], (x, y, result) => {
        given()
          .a_number(x)
          .and()
          .another_number(y);

        when().they_are_summed();

        then().the_result_is(result);
      })
    ),
  };
});
  }
}

class SumThenStage extends Stage {
  @State result: number;

  the_result_is(expectedResult: number): this {
    expect(this.result).toEqual(expectedResult);
    return this;
  }
}

scenarios(
  'sum-multiple-stages',
  [SumGivenStage, SumWhenStage, SumThenStage],
  ({ given, when, then }) => {
    return {
      two_numbers_can_be_added: scenario({}, () => {
        given()
          .a_number(1)
          .and()
          .another_number(2);

        when().they_are_summed();

        then().the_result_is(3);
      }),
    };
  }
);
Example #4
0
    });
    return this;
  }

  the_status_code_is(expectedStatusCode: number): this {
    expect(this.statusCode).toEqual(expectedStatusCode);
    return this;
  }
}

scenarios('async', AsyncStage, ({ given, when, then }) => {
  return {
    an_async_scenario_can_be_executed: scenario({}, () => {
      given().the_url('https://jsgiven.org');

      when().making_an_http_request_to_that_url();

      then().the_status_code_is(200);
    }),
  };
});

class PromiseStage extends Stage {
  url: string;
  statusCode: number;

  the_url(url: string): this {
    this.url = url;
    return this;
  }