Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

Commit

Permalink
Fix tests setup
Browse files Browse the repository at this point in the history
  • Loading branch information
gautiselvaraj committed Feb 7, 2018
1 parent 98f5cb6 commit c666fa0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ describe('<Shorten />', () => {
beforeAll(() => {
canUseDOM = ExecutionEnvironment.canUseDOM;
ExecutionEnvironment.canUseDOM = true;
jest
.spyOn(global.window.Element.prototype, 'getBoundingClientRect')
.mockImplementation(() => ({ width: 300 }));
jest.spyOn(global.window, 'getComputedStyle').mockImplementation(() => ({
'font-weight': 400,
'font-style': 'normal',
Expand All @@ -49,12 +46,21 @@ describe('<Shorten />', () => {
}));
});

beforeEach(() => {
jest
.spyOn(global.window.Element.prototype, 'getBoundingClientRect')
.mockImplementation(() => ({ width: 300 }));
});

afterAll(() => {
ExecutionEnvironment.canUseDOM = canUseDOM;
global.window.Element.prototype.getBoundingClientRect.mockRestore();
global.window.getComputedStyle.mockRestore();
});

afterEach(() => {
global.window.Element.prototype.getBoundingClientRect.mockRestore();
});

it('should render a span', () => {
const wrapper = shallow(<Shorten>{testChildren}</Shorten>);
expect(wrapper.type()).toBe('span');
Expand Down Expand Up @@ -228,7 +234,7 @@ describe('<Shorten />', () => {
it('should render original text without ellipsis when on window resize the screen width fits original text', () => {
const wrapper = mount(<Shorten length={2}>{testChildren}</Shorten>);
expect(wrapper.text()).toBe(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. more...'
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris ornare finibus turpis, vel venenatis felis more...'
);

jest
Expand Down

0 comments on commit c666fa0

Please sign in to comment.