ing
This commit is contained in:
parent
1d04c92e97
commit
5b66d0852d
|
@ -1,17 +1,17 @@
|
|||
import { IS_DEV } from './environment'
|
||||
import { IS_DEV } from './environment';
|
||||
|
||||
export class Greeter {
|
||||
constructor (private greeting: string) {}
|
||||
greet () {
|
||||
return `Hello, ${this.greeting}!`
|
||||
return `Hello, ${this.greeting}!`;
|
||||
}
|
||||
|
||||
greetMe () {
|
||||
/* istanbul ignore next line */
|
||||
if (IS_DEV) {
|
||||
console.warn('this method is deprecated, use #greet instead')
|
||||
console.warn('this method is deprecated, use #greet instead');
|
||||
}
|
||||
|
||||
return this.greet()
|
||||
return this.greet();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
jest.mock('../environment.ts', () => ({
|
||||
IS_DEV: true,
|
||||
IS_PROD: false
|
||||
}))
|
||||
IS_PROD: false,
|
||||
}));
|
||||
|
||||
import { Greeter } from '../Greeter'
|
||||
import { Greeter } from '../Greeter';
|
||||
|
||||
describe(`Greeter`, () => {
|
||||
let greeter: Greeter
|
||||
let greeter: Greeter;
|
||||
|
||||
beforeEach(() => {
|
||||
greeter = new Greeter('World')
|
||||
})
|
||||
greeter = new Greeter('World');
|
||||
});
|
||||
|
||||
it(`should greet`, () => {
|
||||
const actual = greeter.greet()
|
||||
const expected = 'Hello, World!'
|
||||
const actual = greeter.greet();
|
||||
const expected = 'Hello, World!';
|
||||
|
||||
expect(actual).toBe(expected)
|
||||
})
|
||||
expect(actual).toBe(expected);
|
||||
});
|
||||
|
||||
it(`should greet and print deprecation message if in dev mode`, () => {
|
||||
const spyWarn = jest.spyOn(console, 'warn')
|
||||
const actual = greeter.greetMe()
|
||||
const expected = 'Hello, World!'
|
||||
const spyWarn = jest.spyOn(console, 'warn');
|
||||
const actual = greeter.greetMe();
|
||||
const expected = 'Hello, World!';
|
||||
|
||||
expect(actual).toBe(expected)
|
||||
expect(actual).toBe(expected);
|
||||
expect(spyWarn).toHaveBeenCalledWith(
|
||||
'this method is deprecated, use #greet instead'
|
||||
)
|
||||
})
|
||||
})
|
||||
'this method is deprecated, use #greet instead',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/** * @internal */
|
||||
export const IS_DEV = process.env.NODE_ENV === 'development'
|
||||
export const IS_DEV = process.env.NODE_ENV === 'development';
|
||||
|
||||
/** * @internal */
|
||||
export const IS_PROD = process.env.NODE_ENV === 'production'
|
||||
export const IS_PROD = process.env.NODE_ENV === 'production';
|
||||
|
|
|
@ -1 +1 @@
|
|||
export { Greeter } from './Greeter'
|
||||
export { Greeter } from './Greeter';
|
||||
|
|
Loading…
Reference in New Issue
Block a user