Skip to content

Commit

Permalink
test: add tests for the initial module code
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkjrs committed Jan 17, 2025
1 parent ae4f3ab commit 2f22724
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
import { myPackage } from '../src';
import { logger } from '../src/index';

describe('index', () => {
describe('myPackage', () => {
it('should return a string containing the message', () => {
const message = 'Hello';
describe('Logger', () => {
let consoleLogSpy: jest.SpyInstance;

const result = myPackage(message);
beforeEach(() => {
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
});

afterEach(() => {
consoleLogSpy.mockRestore();
});

it("should log a message when NODE_ENV is not 'production'", () => {
process.env.NODE_ENV = 'development';
const message = 'Test log message';

logger.log(message);

expect(consoleLogSpy).toHaveBeenCalledWith(
expect.stringMatching(/\[LOG\] .*: Test log message/)
);
});

it("should not log a message when NODE_ENV is 'production'", () => {
process.env.NODE_ENV = 'production';
const message = 'Test log message';

logger.log(message);

expect(result).toMatch(message);
});
expect(consoleLogSpy).not.toHaveBeenCalled();
});
});

0 comments on commit 2f22724

Please sign in to comment.