mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 09:26:06 +08:00
fix: del messageInstance when configuring getContainer (#34123)
* fix: del messageInstance when configuring getContainer * test: move the new test to the bottom of the test lists
This commit is contained in:
parent
6f71af263e
commit
537f4c357b
@ -125,4 +125,35 @@ describe('message.config', () => {
|
|||||||
transitionName: 'ant-move-up',
|
transitionName: 'ant-move-up',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be able to config getContainer, although messageInstance already exists', () => {
|
||||||
|
function createContainer() {
|
||||||
|
const container = document.createElement('div');
|
||||||
|
document.body.appendChild(container);
|
||||||
|
return [
|
||||||
|
container,
|
||||||
|
() => {
|
||||||
|
document.body.removeChild(container);
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
const [container1, removeContainer1] = createContainer();
|
||||||
|
const [container2, removeContainer2] = createContainer();
|
||||||
|
expect(container1.querySelector('.ant-message-notice')).toBeFalsy();
|
||||||
|
expect(container2.querySelector('.ant-message-notice')).toBeFalsy();
|
||||||
|
message.config({
|
||||||
|
getContainer: () => container1,
|
||||||
|
});
|
||||||
|
const messageText1 = 'mounted in container1';
|
||||||
|
message.info(messageText1);
|
||||||
|
expect(container1.querySelector('.ant-message-notice').textContent).toEqual(messageText1);
|
||||||
|
message.config({
|
||||||
|
getContainer: () => container2,
|
||||||
|
});
|
||||||
|
const messageText2 = 'mounted in container2';
|
||||||
|
message.info(messageText2);
|
||||||
|
expect(container2.querySelector('.ant-message-notice').textContent).toEqual(messageText2);
|
||||||
|
removeContainer1();
|
||||||
|
removeContainer2();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -54,6 +54,7 @@ function setMessageConfig(options: ConfigOptions) {
|
|||||||
}
|
}
|
||||||
if (options.getContainer !== undefined) {
|
if (options.getContainer !== undefined) {
|
||||||
getContainer = options.getContainer;
|
getContainer = options.getContainer;
|
||||||
|
messageInstance = null; // delete messageInstance for new getContainer
|
||||||
}
|
}
|
||||||
if (options.transitionName !== undefined) {
|
if (options.transitionName !== undefined) {
|
||||||
transitionName = options.transitionName;
|
transitionName = options.transitionName;
|
||||||
|
Loading…
Reference in New Issue
Block a user