Skip to content

Instantly share code, notes, and snippets.

View odoe's full-sized avatar
👽
It's full of stars

Rene Rubalcava odoe

👽
It's full of stars
View GitHub Profile
// src/tests/unit/widgets/Profile.ts
describe("Profile", () => {
it("default renders correctly", () => {
const h = harness(() => w(Profile, {}));
h.expect(profileAssertion);
});
it("renders given username correctly", () => {
// update the expected result with a given username
const namedAssertion = profileAssertion.setChildren("~welcome", [
"Welcome Kel Varnsen!"
// tests/unit/widgets/Profile.ts
// Add the assertionTemplate module
import assertionTemplate from "@dojo/framework/testing/assertionTemplate";
...
// Create my assertion
const profileAssertion = assertionTemplate(() =>
v("h1", { classes: [css.root], "~key": "welcome" }, ["Welcome Stranger!"])
);
describe("Profile", () => {
it("default renders correctly", () => {
// src/widgets/Profile.ts
export interface ProfileProperties {
username?: string;
}
export default class Profile extends WidgetBase<ProfileProperties> {
protected render() {
const { username } = this.properties;
return v("h1", { classes: [css.root] }, [
`Welcome ${username || "Stranger"}!`
]);
// tests/unit/widgets/Profile.ts
const { describe, it } = intern.getInterface("bdd");
import harness from "@dojo/framework/testing/harness";
import { w, v } from "@dojo/framework/widget-core/d";
import Profile from "../../../src/widgets/Profile";
import * as css from "../../../src/widgets/styles/Profile.m.css";
describe("Profile", () => {
it("default renders correctly", () => {
const h = harness(() => w(Profile, { username: "Dojo User" }));
h.expect(() => v("h1", { classes: [css.root] }, ["Welcome Dojo User!"]));
import { resolve } from 'path';
import { v } from '@dojo/framework/widget-core/d';
import * as sharp from 'sharp';
export default async function (path: string) {
path = resolve(__dirname, path);
// resize my images
const images = [
await sharp(path).resize(200).toBuffer(),
await sharp(path).resize(300).toBuffer(),
await sharp(path).resize(400).toBuffer(),
import WidgetBase from "@dojo/framework/widget-core/WidgetBase";
import { dom } from "@dojo/framework/widget-core/d";
import Block from "@dojo/framework/widget-core/meta/Block";
import { tsx } from "@dojo/framework/widget-core/tsx";
import fromMarkdown from "../blocks/markdown.block";
import * as css from "./styles/About.m.css";
export default class About extends WidgetBase {
protected render() {
const node = document.createElement("div");
// Use my block
import * as fs from 'fs';
import { resolve } from 'path';
import { Converter } from 'showdown';
const mdConverter = new Converter();
export default function (path: string) {
path = resolve(__dirname, path);
const file = fs.readFileSync(path, 'utf8');
// convert Markdown to HTML
const html = mdConverter.makeHtml(file);
return html
import { Store } from "@dojo/framework/stores/Store";
import { StoreContainer } from "@dojo/framework/stores/StoreInjector";
import { APIExplorer } from "../widgets/APIExplorer";
import { State } from "../interfaces";
import {
fetchItemsProcess,
fetchResultProcess
} from "../processes/starwarsProcesses";
const store = new Store();
const registry = registerStoreInjector(store);
class App extends WidgetBase {
protected render() {
return <APIExplorerContainer />;
}
}
const r = renderer(() => <App />);
export const fetchItemsProcess = createProcess("fetch-items", [fetchItems]);
export const fetchResultProcess = createProcess("fetch-result", [fetchResult]);