{"id":24919806,"url":"https://github.com/steinfletcher/apitest-css-selector","last_synced_at":"2025-03-28T10:12:56.787Z","repository":{"id":57519212,"uuid":"248993869","full_name":"steinfletcher/apitest-css-selector","owner":"steinfletcher","description":"CSS selectors for apitest. Useful for asserting on HTML in a HTTP response ","archived":false,"fork":false,"pushed_at":"2022-10-19T14:53:48.000Z","size":31,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-02T10:37:30.093Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/steinfletcher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-21T14:33:37.000Z","updated_at":"2023-03-23T00:20:07.000Z","dependencies_parsed_at":"2022-09-06T05:10:50.978Z","dependency_job_id":null,"html_url":"https://github.com/steinfletcher/apitest-css-selector","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steinfletcher%2Fapitest-css-selector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steinfletcher%2Fapitest-css-selector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steinfletcher%2Fapitest-css-selector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steinfletcher%2Fapitest-css-selector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/steinfletcher","download_url":"https://codeload.github.com/steinfletcher/apitest-css-selector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246009071,"owners_count":20708881,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-02T10:37:32.394Z","updated_at":"2025-03-28T10:12:56.767Z","avatar_url":"https://github.com/steinfletcher.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Test](https://github.com/steinfletcher/apitest-css-selector/workflows/Test/badge.svg)\n\n# apitest-css-selector\n\nAssertions for [apitest](https://github.com/steinfletcher/apitest) using css selectors.\n\n## Examples\n\n### `selector.TextExists`\n\n```go\napitest.New().\n\tHandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\t_, _ = w.Write([]byte(`\u003chtml\u003e\n\t\t\u003chead\u003e\n\t\t\t\u003ctitle\u003eMy document\u003c/title\u003e\n\t\t\u003c/head\u003e\n\t\t\u003cbody\u003e\n\t\t\u003ch1\u003eHeader\u003c/h1\u003e\n\t\t\u003cp\u003eSome text to match on\u003c/p\u003e\n\t\t\u003c/body\u003e\n\t\t\u003c/html\u003e`,\n\t\t))\n\t\tw.WriteHeader(http.StatusOK)\n\t}).\n\tGet(\"/\").\n\tExpect(t).\n\tStatus(http.StatusOK).\n\tAssert(selector.TextExists(\"Some text to match on\")).\n\tEnd()\n```\n\n### `selector.ContainsTextValue`\n\nIf you are selecting a data test id, a convenience method is provided to simplify the query.\n\n```go\napitest.New().\n\tHandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\t_, _ = w.Write([]byte(`\u003chtml\u003e\n\t\u003chead\u003e\n\t\t\u003ctitle\u003eMy document\u003c/title\u003e\n\t\u003c/head\u003e\n\t\u003cbody\u003e\n\t\u003cdiv data-test-id=\"some-test-id\"\u003e\n\t\t\u003cdiv\u003esome content\u003c/div\u003e\n\t\u003c/div\u003e\n\t\u003c/body\u003e\n\t\u003c/html\u003e`,\n\t\t))\n\t\tw.WriteHeader(http.StatusOK)\n\t}).\n\tGet(\"/\").\n\tExpect(t).\n\tStatus(http.StatusOK).\n\tAssert(selector.ContainsTextValue(selector.DataTestID(\"some-test-id\"), \"some content\")).\n\tEnd()\n```\n\n### `selector.FirstTextValue`\n\n```go\napitest.New().\n\tHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\t_, _ = w.Write([]byte(`\u003cdiv class=\"myClass\"\u003econtent\u003c/div\u003e`))\n\t\tw.WriteHeader(http.StatusOK)\n\t})).\n\tGet(\"/\").\n\tExpect(t).\n\tStatus(http.StatusOK).\n\tAssert(selector.FirstTextValue(`.myClass`, \"content\")).\n\tEnd()\n```\n\nsee also `selector.NthTextValue` and `selector.ContainsTextValue`\n\n### `selector.Exists` `selector.NotExists`\n\n```go\napitest.New().\n\tHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\t_, _ = w.Write([]byte(\n\t`\u003cdiv\u003e\n\t\t\u003cdiv class=\"myClass\"\u003etext\u003c/div\u003e\n\t\t\u003cdiv id=\"myId\"\u003etext\u003c/div\u003e\n\t\t\u003cdiv data-test-id=\"product-5\"\u003etext\u003c/div\u003e\n\t\u003c/div\u003e`))\n\t\tw.WriteHeader(http.StatusOK)\n\t})).\n\tGet(\"/\").\n\tExpect(t).\n\tStatus(http.StatusOK).\n\tAssert(selector.Exists(\".myClass\", `div[data-test-id^=\"product-\"]`, \"#myId\")).\n\tAssert(selector.NotExists(\"#notExists\")).\n\tEnd()\n```\n\n### `selector.Selection`\n\nThis exposes `goquery`'s Selection api and offers more flexibility over the previous methods\n\n```go\nAssert(selector.Selection(\".outerClass\", func(selection *goquery.Selection) error {\n\tif test.expectedText != selection.Find(\".innerClass\").Text() {\n\t    return fmt.Errorf(\"text did not match\")\n\t}\n\treturn nil\n})).\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteinfletcher%2Fapitest-css-selector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteinfletcher%2Fapitest-css-selector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteinfletcher%2Fapitest-css-selector/lists"}