Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: trim framework-supplied attributes in CSR #281

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', '');
}
}