Skip to content

Commit

Permalink
chore: trim framework-supplied attributes in CSR (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson authored Jul 9, 2024
1 parent 3a0f5eb commit 053e151
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/@lwc/jest-serializer/src/clean-element-attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { isKnownScopeToken } = require('@lwc/jest-shared');

const ATTRS_TO_REMOVE = [
'lwc:host', // https://github.com/salesforce/lwc/pull/1600
'data-lwc-host-mutated', // https://github.com/salesforce/lwc/pull/4358
];

function cleanElementAttributes(elm) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`serializes a component containing framework-supplied attributes 1`] = `
<serializer-component>
<h1>
Hello world
</h1>
</serializer-component>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { createElement } from 'lwc';
import FrameworkAttrs from '../frameworkAttrs';

it('serializes a component containing framework-supplied attributes', () => {
const elm = createElement('serializer-component', { is: FrameworkAttrs });
document.body.appendChild(elm);

expect(elm).toMatchSnapshot();
});
3 changes: 3 additions & 0 deletions test/src/modules/serializer/frameworkAttrs/frameworkAttrs.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1 {
color: blue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template lwc:render-mode="light">
<h1>Hello world</h1>
</template>
18 changes: 18 additions & 0 deletions test/src/modules/serializer/frameworkAttrs/frameworkAttrs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import { LightningElement } from 'lwc';

export default class FrameworkAttrs extends LightningElement {
static renderMode = 'light';

connectedCallback() {
// Typically this is only added by the framework itself, but here we are explicitly adding it
// to make the test simpler
this.setAttribute('data-lwc-host-mutated', '');
}
}

0 comments on commit 053e151

Please sign in to comment.