小编Joe*_*ner的帖子

Testing svelte components with svelte/store

When testing svelte components, using jest & @testing-library/svelte, the state is shared between tests, is there away to tear down after each test so i have more isolated unit tests.

store/theme

import { writable } from "svelte/store";

export const LOCAL_STORAGE_KEY = "current:theme";

export const THEMES = {
  DARK: "dark",
  LIGHT: "light"
};

export const MATCH_DARK_THEME = "(prefers-color-scheme: dark)";

export const IS_USER_PREFERNCE_DARK =
  window.matchMedia && window.matchMedia(MATCH_DARK_THEME).matches;

export const DEFAULT_THEME =
  localStorage.getItem(LOCAL_STORAGE_KEY) || IS_USER_PREFERNCE_DARK
    ? THEMES.DARK
    : THEMES.LIGHT;

export const theme = …
Run Code Online (Sandbox Code Playgroud)

javascript svelte svelte-component svelte-store testing-library

6
推荐指数
1
解决办法
702
查看次数

在元素上的 ie11/Edge 中设置宽度 - 在严格模式下不允许分配给只读属性

我正在选择一个元素,我需要根据某些规则更改元素的大小,所有这些在主要浏览器中都可以正常工作,但在 ie11/Edge 中它不起作用。

this.visContainer = this.$element[0].querySelector('.am-visualization-render-area__vis-container');
Run Code Online (Sandbox Code Playgroud)

这是出错的地方我试图将值设置为只读属性

 const visContainerBounds = this.visContainer.getBoundingClientRect();
 visContainerBounds.width -= this.marginHorizontal;
 visContainerBounds.height -= this.marginVertical;
Run Code Online (Sandbox Code Playgroud)

这将返回错误

严格模式下不允许分配给只读属性

我也试过

this.visContainer.clientWidth -= this.marginHorizontal;
this.visContainer.clientHeight -= this.marginVertical;
const visContainerBounds = this.visContainer.getBoundingClientRect();
Run Code Online (Sandbox Code Playgroud)

现在根据我的发现,这是由 ie 和 edge 遵循 ECMAScript5 标准引起的,而 chrome ff safari 不在这种情况下。

我的问题是如何在不抛出此错误的情况下设置元素宽度的值?任何帮助表示赞赏。

javascript internet-explorer ecmascript-5

2
推荐指数
1
解决办法
3278
查看次数