Skip to content

Commit

Permalink
Fix context in beforeEach call (unittest) (#266)
Browse files Browse the repository at this point in the history
This was happen by the difference between Jasmin(CodePen) and Jest(Motocal)

It's repored in official jest issue
Jest fixed the re-use of `this` context as bug.
(it's implicitly context binding to use `this` in test code)
so Jasmin's test code does will not work in Jest.

This patch is required in #201
  • Loading branch information
kei-gbf authored Jun 26, 2019
1 parent b310205 commit a2deedc
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/supplemental.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ describe("#calcSupplementalDamage", () => {
// generate temporary vals: [0, 0, 0, 0]
const INITIAL_VALS = (length=4, value=0) => (new Array(length)).fill(value);

let supplementalDamageArray;

beforeEach(() => {
this.supplementalDamageArray = {
supplementalDamageArray = {
"test-buff-a": {
damage: 10,
damageWithoutCritical: 10,
Expand All @@ -25,14 +27,12 @@ describe("#calcSupplementalDamage", () => {

describe("#calcOthersDamage", () => {
it("test single hit supplemental damage", () => {
let {supplementalDamageArray} = this;
let vals = supplemental.calcOthersDamage(supplementalDamageArray, INITIAL_VALS());
expect(vals.length).toBe(4);
expect(vals).toEqual([30, 30, 300, 500]);
});

it("test hp based supplemental damage", () => {
let {supplementalDamageArray} = this;
supplementalDamageArray['test-buff-a']['type'] = 'hp_based';
supplementalDamageArray['test-buff-a']['threshold'] = 0.80;

Expand All @@ -55,7 +55,6 @@ describe("#calcSupplementalDamage", () => {
});

it("test unknown type is ignored", () => {
let {supplementalDamageArray} = this;
supplementalDamageArray['test-buff-a']['type'] = undefined;
supplementalDamageArray['test-buff-b']['type'] = 'othr'; // assume typo case

Expand All @@ -78,7 +77,6 @@ describe("#calcSupplementalDamage", () => {

describe("#calcThirdHitDamage", () => {
it("test third hit supplemental damage", () => {
let {supplementalDamageArray} = this;
supplementalDamageArray['test-buff-a']['type'] = 'third_hit';

// default expectedTurn: 1
Expand All @@ -100,7 +98,6 @@ describe("#calcSupplementalDamage", () => {

// xit -> Skip test, `test.skip` for Jest
xit("test unknown report", () => {
let {supplementalDamageArray} = this;
supplementalDamageArray["test-buff-a"]["type"] = "unknown";

let vals = supplemental._calcDamage(["unknown"], supplementalDamageArray, INITIAL_VALS());
Expand All @@ -113,7 +110,7 @@ describe("#calcSupplementalDamage", () => {

describe("#collectSkillInfo", () => {
beforeEach(() => {
this.supplementalDamageArray = {
supplementalDamageArray = {
"D": { // for checking sort headers
damage: 10,
type: "other",
Expand Down Expand Up @@ -157,7 +154,6 @@ describe("#collectSkillInfo", () => {
// https://jestjs.io/docs/ja/api#testeachtable-name-fn-timeout
// (Jasmine in codepen.io did not support the same method)
it("test damageArray remainHP 100%,50%", () => {
let {supplementalDamageArray} = this;
const toKey = ([key, type, extraValue]) => key;

let supplementalInfo = supplemental.collectSkillInfo(supplementalDamageArray, {remainHP: 1.00});
Expand Down

0 comments on commit a2deedc

Please sign in to comment.