Untitled

 avatar
unknown
typescript
3 years ago
624 B
3
Indexable
import { Rhum } from 'rhum/mod.ts'

class MathService {
  add(num1: number, num2: number): number {
    return num1 + num2;
  }
}

class MyObj {
  constructor(protected service: MathService) { }
  add(num1: number, num2: number): number {
    return this.service.add(num1, num2);
  }
}

const mock = Rhum.mock(MathService).create();

const myObj = new MyObj(mock);

// Assert that the service's add() method was not called yet
Rhum.asserts.assertEquals(mock.calls.add, 0); // pass

// Assert that the service's add() method was called once
myObj.add(1, 1);

Rhum.asserts.assertEquals(mock.calls.add, 1); // pass

Rhum.run()
Editor is loading...