Skip to content
Open
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
19 changes: 19 additions & 0 deletions src/__tests__/native/styled.test.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,25 @@ test.each(["nativeStyleMapping", "nativeStyleToProp"] as const)(
},
);

test("a mapping entry set to undefined maps nothing", () => {
registerCSS(`.subject { color: blue; background-color: red; }`);
const StyledView = styled(View, {
className: {
target: "style",
nativeStyleMapping: {
color: "accessibilityLabel",
backgroundColor: undefined,
},
},
});

render(<StyledView testID={testID} className="subject" />);

const props = screen.getByTestId(testID).props;
expect(props.accessibilityLabel).toBe("#00f");
expect(props.style).toEqual({ backgroundColor: "#f00" });
});

test.each([false, true])(
"current mapping wins over deprecated alias (empty: %s)",
(empty) => {
Expand Down
69 changes: 69 additions & 0 deletions src/__tests__/types/_program.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { join } from "node:path";

import ts from "typescript";

export const root = join(__dirname, "../../..").replaceAll("\\", "/");

// The repository's own compiler options with exactOptionalPropertyTypes on, and a fixture's unused names allowed
export function compilerOptions(): ts.CompilerOptions {
const { config } = ts.readConfigFile(`${root}/tsconfig.json`, (path) =>
ts.sys.readFile(path),
);
const { options } = ts.parseJsonConfigFileContent(config, ts.sys, root);
return {
...options,
exactOptionalPropertyTypes: true,
noUnusedLocals: false,
noUnusedParameters: false,
};
}

export function createProgram(
rootNames: readonly string[],
virtualFiles: Readonly<Record<string, string>> = {},
): ts.Program {
const options = compilerOptions();
const host = ts.createCompilerHost(options, true);

return ts.createProgram(rootNames, options, {
...host,
getCurrentDirectory: () => root,
fileExists: (name) => name in virtualFiles || host.fileExists(name),
readFile: (name) => virtualFiles[name] ?? host.readFile(name),
getSourceFile: (name, languageVersion, ...rest) => {
const text = virtualFiles[name];
return text === undefined
? host.getSourceFile(name, languageVersion, ...rest)
: ts.createSourceFile(name, text, languageVersion, true);
},
});
}

export function createLanguageService(
virtualFiles: Readonly<Record<string, string>>,
): ts.LanguageService {
const options = compilerOptions();

return ts.createLanguageService(
{
getScriptFileNames: () => Object.keys(virtualFiles),
getScriptVersion: () => "1",
getScriptSnapshot: (name) => {
const text = virtualFiles[name] ?? ts.sys.readFile(name);
return text === undefined
? undefined
: ts.ScriptSnapshot.fromString(text);
},
getCurrentDirectory: () => root,
getCompilationSettings: () => options,
getDefaultLibFileName: ts.getDefaultLibFilePath,
fileExists: (name) => name in virtualFiles || ts.sys.fileExists(name),
readFile: (name) => virtualFiles[name] ?? ts.sys.readFile(name),
readDirectory: (path, extensions, excludes, includes, depth) =>
ts.sys.readDirectory(path, extensions, excludes, includes, depth),
directoryExists: (name) => ts.sys.directoryExists(name),
getDirectories: (name) => ts.sys.getDirectories(name),
},
ts.createDocumentRegistry(),
);
}
Loading