File

test/constants/MockService.ts

Index

Properties

Indexable

[key: string]: number | string

Properties

age
age: number
Type : number
name
name: string
Type : string
place
place: string
Type : string
export interface MockState {
  name: string;
  age: number;
  place: string;
  [key: string]: number | string;
}

export const mockState1: MockState = {
  name: "Mani",
  age: 25,
  place: "Hyderabad",
  address: "0x987654321",
  phone: "987654321",
};

export const mockState2: MockState = {
  name: "Chandra",
  age: 24,
  place: "Boston",
  address: "0x123456789",
  phone: "123456789",
};
export const mockState3: MockState = {
  name: "John",
  age: 20,
  place: "London",
  address: "0x123456789",
  phone: "123456789",
};

export class MockService {
  state: MockState;
  lastState: MockState;

  constructor(_state: MockState) {
    this.state = {
      ..._state,
    };
    this.lastState = { ...this.state };
  }

  changeState(name: string, value: number | string): void {
    this.lastState = { ...this.state };
    this.state[name] = value;
  }

  getState(): MockState {
    return this.state;
  }

  revertToPreviousState(): MockState {
    this.state = { ...this.lastState };
    return this.state;
  }

  revertToState(state: MockState): MockState {
    this.state = { ...state };
    return this.state;
  }
}

results matching ""

    No results matching ""