Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot committed Oct 17, 2024
1 parent eca4283 commit f30b9a1
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 38 deletions.
14 changes: 7 additions & 7 deletions packages/mui-material/src/Slide/Slide.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ describe('<Slide />', () => {

setProps({ in: true });

expect(nodeEnterTransformStyle).to.equal(`translateX(${global.innerWidth - 300}px)`);
expect(nodeEnterTransformStyle).to.equal(`translateX(${globalThis.innerWidth - 300}px)`);
});

it('should set element transform and transition in the `right` direction', () => {
Expand Down Expand Up @@ -368,7 +368,7 @@ describe('<Slide />', () => {

setProps({ in: true });

expect(nodeEnterTransformStyle).to.equal(`translateY(${global.innerHeight - 200}px)`);
expect(nodeEnterTransformStyle).to.equal(`translateY(${globalThis.innerHeight - 200}px)`);
});

it('should set element transform and transition in the `down` direction', () => {
Expand Down Expand Up @@ -425,7 +425,7 @@ describe('<Slide />', () => {

setProps({ in: true });

expect(nodeEnterTransformStyle).to.equal(`translateY(${global.innerHeight + 100}px)`);
expect(nodeEnterTransformStyle).to.equal(`translateY(${globalThis.innerHeight + 100}px)`);
});

it('should set element transform in the `left` direction when element is offscreen', () => {
Expand All @@ -444,7 +444,7 @@ describe('<Slide />', () => {

setProps({ in: true });

expect(nodeEnterTransformStyle).to.equal(`translateX(${global.innerWidth + 100}px)`);
expect(nodeEnterTransformStyle).to.equal(`translateX(${globalThis.innerWidth + 100}px)`);
});
});

Expand All @@ -465,7 +465,7 @@ describe('<Slide />', () => {

setProps({ in: false });

expect(nodeExitingTransformStyle).to.equal(`translateX(${global.innerWidth - 300}px)`);
expect(nodeExitingTransformStyle).to.equal(`translateX(${globalThis.innerWidth - 300}px)`);
});

it('should set element transform and transition in the `right` direction', () => {
Expand Down Expand Up @@ -503,7 +503,7 @@ describe('<Slide />', () => {

setProps({ in: false });

expect(nodeExitingTransformStyle).to.equal(`translateY(${global.innerHeight - 200}px)`);
expect(nodeExitingTransformStyle).to.equal(`translateY(${globalThis.innerHeight - 200}px)`);
});

it('should set element transform and transition in the `down` direction', () => {
Expand Down Expand Up @@ -612,7 +612,7 @@ describe('<Slide />', () => {
style: {},
};
setTranslateValue('up', element);
expect(element.style.transform).to.equal(`translateY(${global.innerHeight - 780}px)`);
expect(element.style.transform).to.equal(`translateY(${globalThis.innerHeight - 780}px)`);
});

it('should do nothing when visible', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-material/src/internal/SwitchBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ describe('<SwitchBase />', () => {

expect(() => {
setProps({ checked: true });
global.didWarnControlledToUncontrolled = true;
globalThis.didWarnControlledToUncontrolled = true;
}).toErrorDev([
reactMajor === 16 &&
'Warning: A component is changing an uncontrolled input of type checkbox to be controlled.',
Expand All @@ -434,7 +434,7 @@ describe('<SwitchBase />', () => {

expect(() => {
setProps({ checked: undefined });
global.didWarnControlledToUncontrolled = true;
globalThis.didWarnControlledToUncontrolled = true;
}).toErrorDev([
reactMajor === 16 &&
'Warning: A component is changing an uncontrolled input of type checkbox to be controlled.',
Expand Down
55 changes: 29 additions & 26 deletions packages/mui-material/src/internal/animate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,37 @@ describeSkipIf(isJSDOM || isSafari)('animate', () => {
}
});

it('should work', (done) => {
container.scrollLeft = 200;
expect(container.scrollLeft).to.equal(200);
animate('scrollLeft', container, 300, {}, (err) => {
expect(err).to.equal(null);
expect(container.scrollLeft).to.equal(300);
done();
});
});
it('should work', () =>
new Promise((done) => {
container.scrollLeft = 200;
expect(container.scrollLeft).to.equal(200);
animate('scrollLeft', container, 300, {}, (err) => {
expect(err).to.equal(null);
expect(container.scrollLeft).to.equal(300);
done();
});
}));

it('should work when asking for the current value', (done) => {
container.scrollLeft = 200;
expect(container.scrollLeft).to.equal(200);
animate('scrollLeft', container, 200, {}, (err) => {
expect(err.message).to.equal('Element already at target position');
it('should work when asking for the current value', () =>
new Promise((done) => {
container.scrollLeft = 200;
expect(container.scrollLeft).to.equal(200);
done();
});
});
animate('scrollLeft', container, 200, {}, (err) => {
expect(err.message).to.equal('Element already at target position');
expect(container.scrollLeft).to.equal(200);
done();
});
}));

it('should be able to cancel the animation', (done) => {
container.scrollLeft = 200;
expect(container.scrollLeft).to.equal(200);
const cancel = animate('scrollLeft', container, 300, {}, (err) => {
expect(err.message).to.equal('Animation cancelled');
it('should be able to cancel the animation', () =>
new Promise((done) => {
container.scrollLeft = 200;
expect(container.scrollLeft).to.equal(200);
done();
});
cancel();
});
const cancel = animate('scrollLeft', container, 300, {}, (err) => {
expect(err.message).to.equal('Animation cancelled');
expect(container.scrollLeft).to.equal(200);
done();
});
cancel();
}));
});
14 changes: 14 additions & 0 deletions packages/mui-material/vitest.config.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { mergeConfig, defineProject } from 'vitest/config';
import sharedConfig from '../../vitest.shared';

export default mergeConfig(
sharedConfig,
defineProject({
test: {
browser: {
...sharedConfig.test.browser,
enabled: true,
},
},
}),
);
6 changes: 3 additions & 3 deletions vitest.shared.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineProject, configDefaults } from 'vitest/config';
import { configDefaults, UserWorkspaceConfig } from 'vitest/config';
import * as path from 'path';

const MONOREPO_ROOT = path.resolve(__dirname, '.');

export default defineProject({
export default {
test: {
exclude: ['build', '**/*.spec.*'],
globals: true,
Expand Down Expand Up @@ -57,4 +57,4 @@ export default defineProject({
include: /.*\.[jt]sx?$/,
exclude: [],
},
});
} satisfies UserWorkspaceConfig;
1 change: 1 addition & 0 deletions vitest.workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { defineWorkspace } from 'vitest/config';
export default defineWorkspace([
// matches every folder inside the `packages` and `packages-internal` folders containing a config file
'{packages,packages-internal}/*/vitest.config.ts',
// '{packages,packages-internal}/*/vitest.config.browser.ts',
]);

0 comments on commit f30b9a1

Please sign in to comment.