我使用createSelector从@ngrx/store选择对象的从我的店里的数组.
我的应用程序编译,但我收到错误
Argument of type 'MemoizedSelector<ICommonAppState, IMenuItemsObject[]>' is not assignable to parameter of type 'string'.
Run Code Online (Sandbox Code Playgroud)
navigation.selectors.ts
import { createSelector } from '@ngrx/store';
import { REDUCER_KEY } from './navigation.constants';
import { ICommonAppState } from './../../app.state';
import { INavigationState } from './navigation.reducer';
const getStore = (state: ICommonAppState) => state[REDUCER_KEY];
export const navigationItems = createSelector(getStore, (state: INavigationState) => state.items);
Run Code Online (Sandbox Code Playgroud)
navigation.component.ts
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import { Component, OnInit } from '@angular/core'; …Run Code Online (Sandbox Code Playgroud) 我正在尝试将Jest和Enzyme添加到React webpack项目中.
一切正常,直到我将测试添加到组件,并使用样式表导入谷歌字体.
我得到的错误是:
? Test suite failed to run
/Users/dev/Code/Git/react-redux-webpack/src/App.sass:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){@import url('https://fonts.googleapis.com/css?family=Barlow+Condensed')
^
SyntaxError: Invalid or unexpected token
Run Code Online (Sandbox Code Playgroud)
sass文件看起来像:
@import url('https://fonts.googleapis.com/css?family=Barlow+Condensed')
body
background: #f9f9f9
color: #444444
font-family: 'Barlow Condensed', sans-serif
text-align: center
.container
width: 100%
max-width: 960px
margin: 0 auto
.container__logo--image
position: absolute
top: 50%
left: 50%
margin-left: -75px
margin-top: -75px
Run Code Online (Sandbox Code Playgroud)
我的.babelrc:
{
"presets": [
"react",
"stage-0",
[
"env",
{
"targets": {
"node": "6.10",
"browsers": ["last 2 versions", "safari >= 7"]
}
}
]
],
"plugins": ["transform-class-properties"]
}
Run Code Online (Sandbox Code Playgroud)
我在webpack中拥有所有必需的加载器,我可以整天构建和服务sass而没有任何问题.这是我正在努力的Jest的介绍. …
我目前正在将 Express API 转移到 Golang 实现。
在 Express 中,如果我想返回一个简单的临时 json 响应,我可以这样做
app.get('/status', (req, res) => res.json({status: 'OK'}))
Run Code Online (Sandbox Code Playgroud)
但是,我很难在 Go 中理解这一点。
我需要为这个简单的响应创建一个结构吗?
我正在尝试这样的事情
func getStatus(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode({status: "OK"})
}
Run Code Online (Sandbox Code Playgroud)
但这显然行不通。
我正在使用Angular 6和NgRX 6。
我有一个看起来像这样的减速器-
export interface IFlexBenefitTemplateState {
original: IFlexBenefitTemplate;
changes: IFlexBenefitTemplate;
count: number;
loading: boolean;
}
export const INITIAL_STATE: IFlexBenefitTemplateState = {
original: null,
changes: null,
count: 0,
loading: true,
};
export default (state = INITIAL_STATE, { type, payload }) => {
switch (type) {
case STAGE_TEMPLATE_CHANGE:
const pendingChanges = Object.assign({}, state.changes.sections);
const newSection = Object.assign({}, pendingChanges[payload.key], payload, {
changeType: 'updated',
});
return {
...state,
changes: {
sections: Object.assign({}, pendingChanges, { [payload.key]: { ...newSection } }),
},
count: !pendingChanges[payload.key].hasOwnProperty('changeType') …Run Code Online (Sandbox Code Playgroud) 我有一个始终采用此格式的 URL
http://domain.tld/foo/bar/boo
http://www.domain.tld/foo/bar/boo
http://sub.domain.tld/foo/bar/boo
http://www.sub.domain.tld/foo/bar/boo
我想使用正则表达式bar从 url 中提取,无论格式如何。
我正在使用 JavaScript。
我尝试使用类似的方法来分解网址
var x = 'http://domain.tld/foo/bar/boo`'
x.split(/^((http[s]?):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/g)
Run Code Online (Sandbox Code Playgroud)
但这并没有真正起作用,也没有帮助,因为当我真的只需要值时,我似乎得到了一个数组或项目bar
我有一个使用Angular 6和NgRX 6的角度应用程序。
我有一个身份服务器,通过隐式流程与之对话,一旦重定向回我的应用程序,我的令牌响应等仍在导航栏中。
我想从网址中清除该片段,并继续沿我的路线行驶。
例如
http://foo.com/bar/boo#key=value
Run Code Online (Sandbox Code Playgroud)
完成并离开后,我想清除此问题
http://foo.com/bar/boo
Run Code Online (Sandbox Code Playgroud)
我正在处理如下效果
@Effect({ dispatch: false })
persistSessionTokens$: Observable<void> = this.actions$.pipe(
ofType<ActionWithPayload>(SET_SESSION_TOKENS),
map(action => action.payload),
tap(tokens => {
persist(ID_TOKEN_STORAGE_KEY, tokens[ID_TOKEN_STORAGE_KEY]);
persist(ACCESS_TOKEN_STORAGE_KEY, tokens[ACCESS_TOKEN_STORAGE_KEY]);
const url = this.router.url;
this.router.navigate([url], { replaceUrl: true });
}),
catchError(error => of({ type: SET_TOKEN_FAILURE, payload: error }))
);
Run Code Online (Sandbox Code Playgroud)
但这将我重定向到
http://foo.com/bar/
在这种情况下,我的应用程序的基本href为 bar
boo 是我的房客的名字,因此在URL中保留此结构很重要。
我有一个服务类,我想断言两件事
这是我的班级
protocol OAuthServiceProtocol {
func initAuthCodeFlow() -> Void
func renderOAuthWebView(forService service: IdentityEndpoint, queryitems: [String: String]) -> Void
}
class OAuthService: OAuthServiceProtocol {
fileprivate let apiClient: APIClient
init(apiClient: APIClient) {
self.apiClient = apiClient
}
func initAuthCodeFlow() -> Void {
}
func renderOAuthWebView(forService service: IdentityEndpoint, queryitems: [String: String]) -> Void {
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试
class OAuthServiceTests: XCTestCase {
var mockAPIClient: APIClient!
var mockURLSession: MockURLSession!
var sut: OAuthService!
override func setUp() {
mockAPIClient = APIClient()
mockAPIClient.session = MockURLSession(data: nil, urlResponse: …Run Code Online (Sandbox Code Playgroud) 我目前正在编写Auth0教程,位于此处:
https://auth0.com/docs/quickstart/spa/react/04-authorization
并且我正努力在管理员用户的上下文中理解范围的概念.
具体来说,以下文字......
由于此范围表示用户具有对数据的只读访问权限,因此可能认为用户具有某种"常规用户"访问级别.
如果您希望某些用户具有对同一资源的写访问权限,从而具有某种"管理员"访问级别,您可以考虑引入write:messages范围.
通过将write:messages作为范围添加到我的控制面板中的api,可以为每个用户请求并设置它.
这根本感觉不对.所以我试图通过规则解决这个问题.
function (user, context, callback) {
if(user.app_metadata.roles.indexOf('admin') > -1) {
console.log(context);
context.accessToken.scope = 'write:messages';
}
callback(null, user, context);
}
Run Code Online (Sandbox Code Playgroud)
在我的app_metadata对象中,我给了我的管理员用户,admin的角色.此规则有效,现在登录时,开发工具中显示的范围是"write:messages".
但是,现在已删除了初始范围,例如"openid read:messages"等
我哪里错了?如果用户是管理员,我想分配添加到现有范围.
这是范围/索赔的正确过程吗?
假设我有一个返回a的方法,tuple并且该元组有一个键.如何使用密钥而不是索引或位置访问该元组?
import Cocoa
func getValues() -> (Int, Int) {
return (firstVal: 1, secondVal: 2)
}
let result = getValues()
print(result)
print(result.firstVal)
Run Code Online (Sandbox Code Playgroud)
在上面print(result)返回元组,减去键并print(result.firstVal)抛出错误.
error: Tuples.playground:3:7: error: value of tuple type '(Int, Int)' has no member 'firstVal'
print(result.firstVal)
^ ~~~~~~~~
Run Code Online (Sandbox Code Playgroud) 我想加载一个 JSON 文件并将其转换为数据作为我的单元测试的一部分。
这样我就可以断言我的服务如何处理响应,但是我不想用大量的 json 块填充每个测试用例。我希望将文件保存在与测试用例相同的目录中,但是尝试运行测试会引发异常,因为找不到文件。
func test_ViewDidLoad_CallsContentService() {
let contentExpectation = expectation(description: "FetchContentEntry")
let httpClient = HTTPClient()
let response = createURLResponse(forUrl: "https://foo.bar", withStatusCode: 200)
httpClient.session = MockURLSession(data: mockContentData, urlResponse: response, error: nil)
.....
}
Run Code Online (Sandbox Code Playgroud)
我的文件被引用为
extension ContentSceneTests {
.........
var mockContentData: Data {
let data = try! Data(contentsOf: URL(fileURLWithPath: "./ContentResponse.json"), options: .alwaysMapped)
return data
}
}
Run Code Online (Sandbox Code Playgroud)
这些文件彼此相邻,例如
ContentSceneTests.swift
内容响应文件
我正在尝试部署nginxdocker 映像。我需要创建一个端点以供我的就绪探针使用,这应该是一个/healthz返回 200 / OK的简单端点。
我已经尝试了下面的方法,但是这会导致浏览器下载包含响应的文件,而不是将其呈现为 doc。
server {
listen 80;
server_name localhost;
location /healthz {
return 200 "OK\n";
}
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri /index.html;
}
# redirect server error pages
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Run Code Online (Sandbox Code Playgroud) 我的单元测试中有一个辅助方法:
func expect(_ sut: CompanyStore, toRetrieve expectedResult: RetrieveCacheResult, when action: @escaping (() -> Void), file: StaticString = #file, line: UInt = #line) {
let exp = expectation(description: "await completion")
sut.retrieve { retrievedResult in
switch (expectedResult, retrievedResult) {
case (.empty, .empty), (.failure, .failure):
break
case let (.found(retrieved), .found(expected)):
XCTAssertEqual(retrieved.item, expected.item, file: file, line: line)
XCTAssertEqual(retrieved.timestamp, expected.timestamp, file: file, line: line)
default:
XCTFail("Expected to retrieve \(expectedResult), got \(retrievedResult) instead", file: file, line: line)
}
exp.fulfill()
}
action()
wait(for: [exp], timeout: 1.0)
} …Run Code Online (Sandbox Code Playgroud) swift ×4
angular ×3
ios ×2
javascript ×2
ngrx ×2
tuples ×2
typescript ×2
unit-testing ×2
xctest ×2
auth0 ×1
docker ×1
enzyme ×1
git ×1
go ×1
jestjs ×1
json ×1
nginx ×1
nginx-config ×1
reactjs ×1
regex ×1
scope ×1
tdd ×1
webpack ×1
xctestcase ×1