在settings.json
有可能只能格式化*.ts
文件有:
"[typescript]": {
"editor.formatOnSave": true
}
Run Code Online (Sandbox Code Playgroud)
但我无法让它为*.tsx
文件工作。
我目前正在与Gatsby创建共享按钮,并希望根据当前网址分享内容,该网址会根据环境和当前网页而变化.使用GoHugo可以调用它{{ .Permalink }}
.有谁知道如何用盖茨比做到这一点?
我有一个ShareButtons组件,它是BlogPostTemplate的子组件.
如果我npm run build
使用 SvelteKit 运行,它似乎包含该src
文件夹中的所有文件。是否可以排除某种文件类型(例如*test.js
)?
选择演示应用程序 npm init svelte@next my-app
添加以下代码到src/routes/todos/foo.test.js
describe('foo', () => {
it('temp', () => {
expect(true).toBe(false)
})
})
Run Code Online (Sandbox Code Playgroud)
npm run build
npm run preview
结果:describe is not defined
将测试移至外部src
当我尝试添加新的资源文件(即文件>新建>Android 资源文件)时,“源集:”丢失。有谁知道为什么会这样?
我有一个简单的功能:
scrollToSecondPart() {
this.nextPartRef.current.scrollIntoView({ behavior: "smooth" });
}
Run Code Online (Sandbox Code Playgroud)
我想使用Jest进行测试。当我调用函数时,出现以下错误:
TypeError: Cannot read property 'scrollIntoView' of null
Run Code Online (Sandbox Code Playgroud)
该代码在应用程序中效果很好,但在单元测试中效果不佳。这是单元测试:
it("should scroll to the second block", () => {
const scrollToSecondPart = jest.spyOn(LandingPage.prototype, 'scrollToSecondPart');
const wrapper = shallow(<LandingPage />);
const instance = wrapper.instance();
instance.scrollToSecondPart();
expect(scrollToSecondPart).toHaveBeenCalled();
});
Run Code Online (Sandbox Code Playgroud)
我想问题是单元测试无法访问,this.nextPartRef
但我不知道该如何模拟该元素。顺便说一句,我正在使用https://reactjs.org/docs/refs-and-the-dom.html中描述的“引用” (我正在使用React.createRef()
)。
谢谢!
根据redux 文档:“虽然使用 RTK 查询管理缓存数据来将响应存储在规范化查找表中的需要较少,但如果需要,可以利用 TransformResponse 来做到这一点。”
当我将以下代码添加到我的时,package.json
我收到一条错误消息,指出它不受支持:
"jest": {
"resetMocks": true
},
Run Code Online (Sandbox Code Playgroud)
提前致谢!
如何模拟withStyles
in 的实现material-ui/core/styles.js
?
这是测试:
import React from 'react'
import { shallow } from 'enzyme'
import { withStyles } from '@material-ui/core/styles'
import TempComponent from './TempComponent'
jest.mock('@material-ui/core')
it('renders correctly', () => {
const withStylesFake = styles =>
component => (
component
)
withStyles.mockImplementation(withStylesFake)
const wrapper = shallow(<TempComponent />)
expect(wrapper).toMatchSnapshot()
})
Run Code Online (Sandbox Code Playgroud)
这是代码:
import React from 'react'
import { withStyles } from '@material-ui/core/styles'
const TempComponent = () => (
<button>Click Me!</button>
)
export default withStyles({})(TempComponent)
Run Code Online (Sandbox Code Playgroud)
这是错误:
TypeError: _styles.withStyles.mockImplementation is not a …
Run Code Online (Sandbox Code Playgroud) $lib
当我尝试在玩笑中运行使用别名导入文件的测试时,jest
无法运行并出现错误Cannot find module '$lib/...'
。
Java中是否可以获取当前的排序顺序?
以下是汽车按年份排序的示例:
<p:column headerText="Year" sortBy="#{car.year}">
<h:outputText value="#{car.year}" />
</p:column>
Run Code Online (Sandbox Code Playgroud)
通过扩展LazyDataModel<T>
可以重写以下方法:
public List<T> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,Object> filters) {
throw new UnsupportedOperationException("Lazy loading is not implemented.");
}
Run Code Online (Sandbox Code Playgroud)
但我想知道如何在不使用 LazyDataModel 的情况下做到这一点。
谢谢!
jestjs ×4
reactjs ×3
sveltekit ×2
android ×1
build.gradle ×1
gatsby ×1
gradle ×1
java ×1
jsf ×1
material-ui ×1
mocking ×1
primefaces ×1
react-tsx ×1
redux ×1
rtk-query ×1
sorting ×1
typescript ×1
vite ×1