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:
TrickyPi 2022-02-21 12:31:39 +08:00 committed by GitHub
parent 6f71af263e
commit 537f4c357b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -125,4 +125,35 @@ describe('message.config', () => {
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();
});
});

View File

@ -54,6 +54,7 @@ function setMessageConfig(options: ConfigOptions) {
}
if (options.getContainer !== undefined) {
getContainer = options.getContainer;
messageInstance = null; // delete messageInstance for new getContainer
}
if (options.transitionName !== undefined) {
transitionName = options.transitionName;